简体   繁体   English

为什么我的$ _SESSION ['user_login']不能更改为true?

[英]why my $_SESSION['user_login'] not change to true?

in index.php 在index.php中

<?php
  session_start();
  $_SESSION['user_login'] = false;
}
?>

<li>
    <div style="margin-left: 15px ;margin-right:15px ; text-align: center">
       <?php
       if (!$_SESSION['user_login']){
           echo '<a href="View/login.php" class="btnprofile" style="background-image:url(./img/defaullt_profile.jpg)" ></a>';
       }
       else{
           echo '<a href="View/profile.php" class="btnprofile" style="background-image:url(coba.jpg)" ></a>';
       }
       ?>
     </div>
</li>

in login.php 在login.php中

just see when the $cekrole == 'member' 只看何时$ cekrole =='member'

<?php
include_once '../Dao/UserDaoImpl.php';
include_once '../Entity/USER.php';
include_once '../util/PDOUTIL.php';
session_start();
$loginPressed = filter_input(INPUT_POST, 'btnLogin');
if (isset($loginPressed)) {
    $userDao = new UserDaoImpl();
    $username = filter_input(INPUT_POST, 'txtUsername');
    $password = filter_input(INPUT_POST, 'txtPassword');
    $md5Password = md5($password);
    $userLogin = new User();
    $userLogin->setUsername($username);
    $userLogin->setPassword($md5Password);
    /* @var $arrResult User */
    $arrResult = $userDao->login($userLogin);
    $longname = $arrResult['longname'];
    $email = $arrResult['email'];
    $gender = $arrResult['gender'];
    $dateofbirth = $arrResult['dateofbirth'];
    $cekrole = $arrResult['role'];
    $profile = $arrResult['profile'];
    if (isset($arrResult) && !empty($arrResult['name'])) {
        if ($cekrole == 'admin') {
            $_SESSION['user_login'] = TRUE;
            $_SESSION['user_name'] = $arrResult['username'];
            header('location:homeadmin.php');
        } elseif ($cekrole == 'employee') {
            $_SESSION['user_login'] = TRUE;
            $_SESSION['user_name'] = $arrResult['username'];
            $_SESSION['namauser'] = $username;
            header('location:homeemployee.php');
        } elseif ($cekrole == 'member') {
            $_SESSION['user_login'] = TRUE;
            $_SESSION['user_name'] = $arrResult['username'];
            $_SESSION['profile'] = $profile;
            $_SESSION['longname'] = $longname;
            $_SESSION['email'] = $email;
            $_SESSION['dateofbirth'] = $dateofbirth;
            $_SESSION['gender'] = $gender;
            header('location:../index.php');
        }
    }
    else{
        $message = 'Id atau Password salah';
        echo "<script type='text/javascript'>alert('$message');</script>";
    }
}
?>

can someone help me :( , see the login.php and just see when role == member 有人可以帮助我:(,请参阅login.php,仅查看角色==成员的时间

why when the login is true and set session['user_login'] = TRUE and header to index.php, but the session['user_login'] in index.php still FALSE 为什么当登录为true并设置session ['user_login'] = TRUE并将标头设置为index.php时,但index.php中的session ['user_login']仍然为FALSE

sory my english so bad :D 让我的英语太糟糕了:D

<?php
    session_start();
    if (!isset($_SESSION['user_login'])) { //if session doesn't exist, set user_login to false
        $_SESSION['user_login'] = false;
    }
?>

So when session doesn't exist yet, or user isn't logged then $_SESSION['user_login'] = false else $_SESSION['user_login'] is true and you can continue your workflow. 因此,当会话尚不存在或用户未登录时, $_SESSION['user_login'] = false否,否则$ _SESSION ['user_login']为true,您可以继续工作流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM