會話變量沒有在第一次設置。從action.php到employee.php,但是在employee.php中,$ _SESSION ['EmpID']第一次登錄時什麼都不顯示。如果我註銷並重新登錄,則可以正常工作。在localhost中正常工作。PHP SESSION變量第一次不工作
action.php
<?php
session_start();
if(isset($_POST['UserID'])&&isset($_POST['Password']))
{
$id = $_POST['UserID'];
$pass = $_POST['Password'];
$result = mysqli_query($con,"select * from auth_det where UserName='$id' and Password='$pass'");
if(mysqli_num_rows($result)>0)
{
$row = mysqli_fetch_array($result);
//echo $row['UserID'];
//echo $row['Password'];
$_SESSION['UserName']=$id;
$_SESSION['EmpID'] = $row['EmpID'];
$_SESSION['is_auth'] = true;
$_SESSION['User'] = "Emp";
echo "<script type='text/javascript'>window.location.href = 'Employee/employee.php'; </script>";
exit();
}
logout.php
<?php
session_start();
session_destroy();
echo "<script type='text/javascript'> document.location = '../login.php'; </script>";
?>
employee.php
session_start();
$EmpID=$_SESSION['EmpID'];
echo "EmpID=".$EmpID;
if(!isset($_SESSION['EmpID']))
{
echo "<script type='text/javascript'> window.location.href = 'logout.php'; </script>";
}
沒有代碼的頂部寫
session_start();
=沒問題 – nogad顯示你的代碼 – Dave
你能更具體嗎?您的問題太寬泛,請提供代碼和方案。 – Ajir