我正在創建登錄腳本。標題都可以工作,但顯然$ _SESSION保持空白。有誰知道這可能是爲什麼?
$db = dbConnection();
// username and password sent from form
$myusername= $_POST['myusername'];
$mypassword= md5($_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 " .$members. " WHERE BINARY `username`= '".$myusername."' and BINARY `password`= '".$mypassword."'";
$result = $db->query($sql);
// Mysql_num_row is counting table row
$count=$result->rowCount();
// Fetch this accounts row from db
$row = $result->fetch(PDO::FETCH_ASSOC);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
$_SESSION['username'] = $myusername;
$_SESSION['privileges'] = $row['privileges'];
$_SESSION['email'] = $row['email'];
header("location:index.php");
}
假設你有'session_start();'隱藏在某處? –