我用dreamweaver CS4 做的一个PHP登录界面。但是运行登录界面的时候提示出错,我在网上找了一下,没有找到解决的方案,希望出过类似问题的朋友能够指点一下。错误提示:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\jiajia\login.php:1) in C:\xampp\htdocs\jiajia\login.php on line 0Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\jiajia\login.php:1) in C:\xampp\htdocs\jiajia\login.php on line 0Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\jiajia\login.php:1) in C:\xampp\htdocs\jiajia\login.php on line 73
                   代码如下:
<?php virtual('/jiajia/Connections/conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "level";
  $MM_redirectLoginSuccess = "checkmsg.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_conn, $conn);
  
  $LoginRS__query=sprintf("SELECT username, password, level FROM member WHERE username=%s AND password=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $conn) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'level');
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;           if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
.dd {
font-size: 36px;
}
-->
</style>
</head><body>
                   
 <p>&nbsp;</p>
 <p>&nbsp;        </p>
  
   
     
  
 <table width="992" height="236" border="1">
   <tr>
     <td height="230">                             
     <p class="dd">            请先登录  </p>
<form id="form2" name="form2" method="POST" action="<?php echo $loginFormAction; ?>"> 
       <p>                       账号:
         <input type="text" name="username" id="username" />
       </p>
       <p>                       密码:
         <input type="text" name="password" id="password" />
       </p>
       <p>                          
         <input type="submit" name="button" id="button" value="登录" />
       </p>
       <p>&nbsp;</p>
     </form></td>
   </tr>
 </table>
</body>
</html>

解决方案 »

  1.   

    <?php
    session_start();
    //保证在第一行
    ?>
    <html> 
    <head>
    <title></title>
    </head><body>
    </body>
    </html>
      

  2.   

    谢谢楼上的大侠,这个问题搞定了。但是还有一点出了错误:
    Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\jiajia\login.php:6) in C:\xampp\htdocs\jiajia\login.php on line 73
                       
    第73行的代码是: header("Location: " . $MM_redirectLoginSuccess );
      

  3.   

    header("Location: ".$MM_redirectLoginSuccess."");
      

  4.   

    header也是一样。必须要放在首行。前面不能有任何输出。你可以这样想:
    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
      }
       echo "<script>window.location.href='".$MM_redirectLoginSuccess." '</script>";
      }下面那句也一样。