我试图创建一个LogIn页面,该页面检查sql数据库中的电子邮件和密码,然后将sql数据库的一些结果分配给php sessions
。问题是,未分配会话。当我使用“注销”按钮(执行注销脚本)并尝试再次登录时,会话分配很完美。
我一直在另一台服务器上学习php,并且该服务器使用另一个php版本( php5.6 )。新的托管公司使用php7.0。我已经检查了php.ini
文件中的会话写路径(如果存在)。我唯一能想到的是LogOut脚本会触发使sessions
可写的内容?道歉,但仍在学习
session_start();
include("db.php");
if (isset($_POST['epos']) and isset($_POST['pass'])){
$thenaamof = $_POST['epos'];
$thepassof = $_POST['pass'];
$_SESSION["agid"] = "";
$_SESSION["agarea"] = "";
$_SESSION["agdrop"] = "";
$_SESSION["agstat"] = "";
$result = mysqli_query($con,"SELECT * FROM tablename WHERE email='$thenaamof' AND pass='$thepassof'")
or die(mysqli_error($con));
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_assoc($result);
$_SESSION["agid"] = $row["id"];
$_SESSION["agarea"] = $row["area"];
$_SESSION["agdrop"] = $row["twnva"];
$_SESSION["agstat"] = $row["status"];
header('Location: https://www.dieplek.php');
exit;
} else {
header('Location: https://www.daaiplek.php');
exit;
}
}
//// the logout script is:
session_start();
$_SESSION["agid"] = "";
$_SESSION["agarea"] = "";
$_SESSION["agdrop"] = "";
$_SESSION["agstat"] = "";
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();