這是我的第一頁。我只是無法讓我的變量到下一頁index.php($ _SESSION ['admin_email'])。變量賦值工作在第一頁上細,在index.php中它總是重定向到的login.phpPHP會話變量不能在兩個頁面工作
<?php
error_reporting(0);
session_start();
include_once('../_inc/_class/Users.php');
$dbUsers = new Users();
$uname = htmlspecialchars($_POST['username']);
$upass = md5($_POST['password']);
if($uname != "" && $upass != "") {
$user = $dbUsers->selectAll("`password` = '".$upass."' and `email` = '".$uname."' and user_type = 'admin'", "1", "");
/*print_r($user);*/
if(!empty($user) && $user[0]->email == $uname && $user[0]->password == $upass) {
$_SESSION['admin_email'] = $user[0]->email;
/*var_dump($_SESSION['admin_email']);*/
}
else {
$_SESSION = array();
session_destroy();
}
}
die(header('Location:../index.php'));
?>
的index.php
<?php
error_reporting(E_ALL);
session_start();
if(!isset($_SESSION['admin_email'])) {
die(header('Location:./login.php'));
}
?>
的新頁面上,做了'的print_r($ _ SESSION);',以瞭解更多信息 – Akintunde007
你'在其他部分確保您不小心使用'session_destroy()你的if語句? –
你確定你的登錄腳本沒有經過if的else部分嗎?嘗試放置一個死亡()在其他.... –