我無法啓動會話,即使此代碼在其他網站中正確運行,但在我構建的網站中,它將無法工作。這是代碼:無法啓動用戶的會話
if(isset($_POST["username"])&& isset($_POST["password"])) {
$manager = preg_replace('#[^A-Za-z0-9\@\-\_\|\,\.\\p{L}\\\\]#i', '', $_POST["username"]);//filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]);// filter everything but numbers and letters
// Connect to the Mysql database
$q = "SELECT * FROM users WHERE username='$manager' AND password='$password' LIMIT 1";
$r = mysqli_query($dbc, $q);
$userCount = mysqli_num_rows($r);
if($userCount == 1) {
while ($user = mysqli_fetch_assoc($r)) {
$id = $user['id'];
$pass = $user['password'];
$us = $user['username'];
}
$_SESSION["id"] = $id;
$_SESSION["manager"] = $us;
$_SESSION["password"] = $pass;
header("location:index.php?page=business");
exit();
} else {
echo 'That information is incorrect,try again <a href="index.php">Click Here</a>';
}
}
直到代碼
$id = $user['id'];
$pass = $user['password'];
$us = $user['username'];
一切正常的一部分,但是之後我設置會話變量:
$_SESSION["id"] = $id;
$_SESSION["manager"] = $us;
$_SESSION["password"] = $pass;
header("location:index.php?page=business");
exit();
沒有會話發現,可以在任何一個幫我?
你有沒有接着說:在session_start()'對你的PHP代碼的頂部? –
您是否在設置會話前將session_start()放入了該頁面 – krishna
您需要在腳本 –