我在页面post.php上遇到会话值问题我验证密码并设置会话值并在页面上chekrole我检查会话是否登录 它总是第一次将会话值清空并且如果我尝试aagain则为true,
post.php中
<?php
ini_set("session.cookie_httponly", 1);
ini_set("session.cookie_secure", 1);
define('MyConst', TRUE);
require_once('includes/db.php');
$user=mysql_real_escape_string($_POST['login']);
$pass=mysql_real_escape_string($_POST['pass']);
$st=$con->stmt_init();
$st->prepare("select PASSWORD from users where USERNAME=?");
$st->bind_param('s',$user);
$st->execute();
$st->bind_result($hpass);
$st->fetch();
$st->close();
if(password_verify($pass, $hpass)){
if(!session_id())
session_start();
$_SESSION['logon']=true;
$_SESSION['time']=time()+7200;
$result=$con->query("select * from users where USERNAME='$user'");
$row=$result->fetch_assoc();
// session values
$_SESSION['user']=$user;
$_SESSION['stname']=$row['STUDENT_NAME'];
$_SESSION['tname']=$row['TEACHER_NAME'];
$_SESSION['tsname']=str_replace("_"," ",$row['TEACHER_NAME']);
$_SESSION['gender']=$row['GENDER'];
$_SESSION['roll']=$row['ROLL'];
$_SESSION['role']=$row['ROLE'];
$_SESSION['stsession']=$row['SESSION'];
$_SESSION['url']=$_SERVER['SERVER_NAME'];
$_SESSION['class']=$row['CLASS'];
$_SESSION['logo']=$row['LOGO'];
header('location: checkrole.php');
}else header('location: login.php');
?>
CHECKROLE.php
<?php
if(!session_id())
session_start();
if(!$_SESSION['logon'])
header("location: index.php");
if($_SESSION['role']=='Student')
header ('location: dashboard.php');
if($_SESSION['role']=='Teacher')
header('location:tdashboard.php');
?>