Cannot send session cache limiter - headers already sent 这句话的意思很明白了,在发出session的时候,头部已经发出了
代码如下 if(isset($_POST['submitted'])){// has been submit //connect database require_once('connect.php'); //instart error $errors=array(); //check email if(empty($_POST['email'])){ $errors[]='email is not null'; }else{ $e=$_POST['email']; } //check password if(empty($_POST['password'])){ $errors[]='password is not null'; }else{ $p=$_POST['password']; } if(empty($errors)){ //if everything is ok
$sql = "SELECT user_id, first_name FROM users WHERE email='$e' AND password=SHA('$p')"; $query=mysql_query($sql); $row=mysql_fetch_array($query); if($row){ //if a recode //SESSION START
session_start(); $_SESSION['user_id']=$row[0]; $_SESSION['first_name']=$row[1]; //url $url='http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']); if((substr($url,-1)=='/') or (substr($url,-1)=='\\')){ $url=substr($url,0,-1); } $url.='/logining.php'; //header("Location:$url"); header("Location: $url"); exit(); }else{ //not recode echo "<h2>system error</h2> <p>meiyou ni yao chaxun de jilu</p> ";
}// end if($row) }//end if empty errors }else{ //if not set submit $errors=NULL; }//end submitted if if(!empty($errors)){ echo '<h1>PAGE ERROR</h1>'; foreach ($errors as $msg){ echo "-$msg".'<br/>'; } exit();
<?php
ob_start();
session_start();
ob_end_flush();
?>
检查下空格!!
这句话的意思很明白了,在发出session的时候,头部已经发出了
if(isset($_POST['submitted'])){// has been submit
//connect database
require_once('connect.php');
//instart error
$errors=array();
//check email
if(empty($_POST['email'])){
$errors[]='email is not null';
}else{
$e=$_POST['email'];
}
//check password
if(empty($_POST['password'])){
$errors[]='password is not null';
}else{
$p=$_POST['password'];
}
if(empty($errors)){ //if everything is ok
$sql = "SELECT user_id, first_name FROM users WHERE email='$e' AND password=SHA('$p')";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
if($row){ //if a recode
//SESSION START
session_start();
$_SESSION['user_id']=$row[0];
$_SESSION['first_name']=$row[1];
//url
$url='http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
if((substr($url,-1)=='/') or (substr($url,-1)=='\\')){
$url=substr($url,0,-1);
}
$url.='/logining.php';
//header("Location:$url");
header("Location: $url");
exit();
}else{ //not recode
echo "<h2>system error</h2>
<p>meiyou ni yao chaxun de jilu</p> ";
}// end if($row)
}//end if empty errors
}else{ //if not set submit
$errors=NULL;
}//end submitted if
if(!empty($errors)){
echo '<h1>PAGE ERROR</h1>';
foreach ($errors as $msg){
echo "-$msg".'<br/>';
}
exit();
}
$page_title = 'Login';
include ('./includes/header.html');
//show form
?>
<h2>LOGIN tt</h2>
<form action="login.php" method="post">
<p>email:
<input type="text" name="email" />
</p>
<p>password:
<input type="password" name="password" />
</p>
<p>
<input type="submit" value="Submit" />
</p>
<input type="hidden" name="submitted" value="TRUE" />
</form><?php
include('includes/footer.html');
?>