PHP SESSION变量第一次不起作用

Session variables are not set at the first time. From action.php it goes to employee.php But in employee.php $_SESSION['EmpID'] shows nothing when I log in for the 1st time. If I log out and log in again then works fine. works fine in localhost.

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>";
}

try to move the session_start() to the action.php file. At first connect php doesn't create a session at action.php Then you get redirected and employee.php starts the session. If you try this again later a session is already open so you have no problems at the action php.

Also think about switching the Javascript Redirect to an header redirect since it still works if the Client disabled Javascript

please check that you did'nt forgot to write session_start(); on the top of action.php page