会话存在但用户名是空白的?

时间:2011-12-16 03:13:31

标签: php session

我有这个应用程序在测试服务器上工作,但不在生产中。生产版本显示登录消息,空白而不是用户名,直到您退出并重新登录为止!测试版本没有这样做,并且在您实际登录之前正确显示登录链接。我没有写代码,所以我很困惑!

第一个文件 - /Staff/Schedule/Schedu-Mod_Input.php

<?php
    if($_SESSION['isLoggedin'] == 'Yes'):
?>
<p>You are logged in as  <b><?php echo $_SESSION['SESS_USER_USERNAME'];?></b></p>
<?php else: ?>
    Please <a href="/Admin/login.php/">login </a>here <br />
<?php endif;?>

会话在名为login.php

的第二个文件中创建
<?php
session_name('SESS_IFTC'); // Set the session name
session_start();
$special_prefix = "";

include($_SERVER['DOCUMENT_ROOT'].$special_prefix.'/Includes/Connect.php');
include($_SERVER['DOCUMENT_ROOT'].$special_prefix.'/Includes/Functions.php');

$shiftdate = $_GET['shiftdate'];
$mod = $_GET['mod'];
if (isset($_POST['username']) && isset($_POST['upassword'])) {
    $query = "SELECT * FROM users WHERE username = '".addslashes($_POST['username'])."' AND password = '".base64_encode($_POST['upassword'])."' AND status='active' ";
    $result = mysql_query($query) or QueryFail($query);
    $row = mysql_fetch_array($result);
    $_SESSION['isLoggedin'] = '';
    $_SESSION['SESS_IS_ADMIN'] = '';

    if(!empty($row) && is_array($row)) // CHECK IS user valid
    {

            $_SESSION['SESS_IS_ADMIN'] = 'No';
            if($row['usertype'] == 'admin') $_SESSION['SESS_IS_ADMIN'] = 'Yes'; 
            $_SESSION['SESS_USER_ID']= $row['id']; 
            $_SESSION['SESS_USER_USERNAME'] = ucfirst($row['username']); 
            $_SESSION['SESS_USER_EMAIL'] = $row['email'];
            $_SESSION['isLoggedin'] = 'Yes';
            //print_r($_SESSION);
            $query = "UPDATE users SET "
                    ." lastaccess = '".date("Y-m-d H:i:s")."' "          
                ." WHERE id = ".$row['id'];
            mysql_query($query);
            if($_REQUEST['mod'] == 'staff'){
                $shiftdate = $_REQUEST['shiftdate'];
                header("Location: /Staff/Schedule/Schedu-Mod_Input.php?shiftdate=$shiftdate");
                exit;
            }
            header("Location: /Staff/Schedule/Schedu-Mod_Input.php");
            exit;   
    }else{
      $errorMsg = "Invalid Username or Password! Please try again";
    }
  }

unset($_SESSION);

?>

出了什么问题?

0 个答案:

没有答案