session没有从登录到主页php传递会话值

时间:2015-11-17 14:58:42

标签: php session

hye guys ..我知道这个问题已经发布了数百万次...我刚接触php btw..right现在我试图使用session来制作多级用户登录表单。但我很困惑为什么我的会话确实有效。 .i已经尝试重定向到登录页面,如果用户还没有登录..如果我尝试从主页运行,似乎代码读取我的会话尚未通过..但问题是它没有重定向到登录表单,即使会话不存在..我已经尝试清除所有的缓存和cookie但仍然没有工作..为我破碎的语言...我希望你们明白我的问题是什么,并告诉我什么是我的代码有问题。

loginFunction.php

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);

@session_start();
include ('Connections/connect.php');

if(isset($_POST['submit'])) {

    $username = $mysqli->real_escape_string($_POST['txtUsername']);
    $password = $mysqli->real_escape_string($_POST['txtPassword']);

    if ($username == "" || $password == "") {
?> 
    <script> alert('Please enter username and password ...') 
    window.location='index.html'</script> 
<?php
} else {

     $query = ("SELECT * FROM tbluser   WHERE username='$username' AND password='$password'");
     $result = $mysqli->query($query);
     $data = $result->fetch_array();
     $count = $result->num_rows;

     if ($count>0) {

        if ($data['role'] == "partner") {

            @$_SESSION['partner'] = $data['userId'];
?> 
            <script>alert('You are log as industrial partner ...')
            window.location='homePartner.html'</script> 
<?php
        } else if ($data['role'] == "student") {

            @$_SESSION['student'] = $data['userId'];
?> 
            <script>alert('You are log as student ...')
            window.location='homeStudent.html'</script>
<?php

         } else if ($data['role'] == "admin") {

            @$_SESSION['admin'] = $data['userId'];
?> 
            <script>alert('You are log as admin ...')
            window.location='homeAdmin.html'</script>
<?php
        } 


    } else {
?> 
            <script>
            alert('Username or password does not match ...')
            window.location='index.html'
            </script> 
<?php
        }
}
}
?> 

homeStudent.html

<?php

session_start();
include ('Connections/connect.php');

if(@$_SESSION['student'] || @$_SESSION['admin'] || @$_SESSION['partner'] ) {

?>
 <html>
   //html stuff
 </html>

<?php

 } else {

     header("location: index.html");
   exit;
  ?> 
        <script>
       alert('Please login first ...')
        </script> 
<?php
}
?>

0 个答案:

没有答案