使用 header() 重定向后,我一直丢失 SESSION 变量。我尝试了在类似问题中找到的所有解决方案,例如每个页面顶部的 session_start() 和 header() 之后的 exit(),但它不起作用。每次我在 succlog.php 页面中收到“id not set”。重定向到 succlog.php 非常完美。你能帮我么?以下是代码:
登录页面:
session_name("session1");
session_start();
..........
$qry = "SELECT * FROM `members` WHERE `usr` = '$username' AND `pass` = '" . md5($password) . "'";
$result = mysql_query($qry);
//Check whether the query was successful or not
if(mysql_num_rows($result) == 1) {
while($row = mysql_fetch_assoc($result)) {
$_SESSION['id'] = $row['id'];
$_SESSION['usr'] = $username;
session_write_close();
header("location: succlog.php"); //Redirect
exit();
}
}
成功日志.php:
session_name("session1");
session_start();
...........
<?php
if(isset($_SESSION['id'])){
echo "id".$_SESSION['id'];
}
else{
echo "id not set";
}
?>