我'管理checklogin.php'執行後啓動會話,但當我嘗試重定向到'login_success.php'我仍然在同一'checklogin.php'頁面。你對我能做什麼有什麼建議嗎?會話啓動失敗後PHP重定向
<?php
ob_start();
$host="";
$username="";
$password="";
$db_name="";
$tbl_name="";
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_start();
$_SESSION['myusername']=$myusername;
$_SESSION['mypassword']=$mypassword;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password. Please try again.";
}
ob_end_flush();
?>
我收到以下錯誤:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /homepages/46/d473160420/htdocs/checklogin.php:58) in /homepages/46/d473160420/htdocs/checklogin.php on line 93
Warning: Cannot modify header information - headers already sent by (output started at /homepages/46/d473160420/htdocs/checklogin.php:58) in /homepages/46/d473160420/htdocs/checklogin.php on line 96
你爲什麼要在這裏控制緩衝區輸出? –
你會建議我在哪裏控制它? – Dan
我只是想知道**爲什麼**你正在控制它 –