doutui8842 2015-11-17 14:58
浏览 23

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

hye guys..i know this question have been post million of times..im new to php btw..right now im trying to make multilevel user login form using session..but im little confused why my session didt work..i already tried to make a redirect to login page if the user is not login yet..it seem the code read that my session does not pass yet if i try to run from the homepage..but the problem is it does not redirect to the login form even the session is not exist..i have tried to clear all the cache and cookies but still did not work..sorry for my broken language..i hope u guys understand what my question is and tell me what is problem with my codes..ty

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 html5+css有人可以帮吗?
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?