为什么我的变量不是用SESSION变量设置的?

时间:2013-07-03 17:18:58

标签: php variables session-variables

我认为这是一个语法问题,但我尝试了几种不同的方法。在IIS 6上运行的PHP 5.4.16(这些不是我的选择)。

我无法将$ usr设置为$ _SESSION ['uid']。我在设置之后立即运行了一个转储,我看到会话数据的uid信息,但$ usr的NULL。语法错了?你觉得怎么样?

function User_CustomValidate(&$usr, &$pwd) {
    session_start(); // Initialize Session data
    ob_start(); // Turn on output buffering
    $appKey = "pwssssssssssssss";
    $safeurl =  'https://safe.ssssss.com/login/sso/SSOService?app=playbooks';
    // first call back after safe login - POST is set
    if ($_POST && isset($_POST['digest'])) 
    {
        $digest = $_POST["digest"];

        // set the session variables ...
        $_SESSION['usernames'] = $_POST["firstname"]." ".$_POST["lastname"];
        $_SESSION['firstname'] = $_POST["firstname"];
        $_SESSION['lastname'] = $_POST["lastname"];
        $_SESSION['email'] = $_POST["email"];
        $_SESSION['uid'] = $_POST["uid"];

        // Needed for key
        $uid = $_POST["uid"];
        $time = $_POST["time"];

        // Read the property file with the key and URL so this won't go into the main code ...
        // this sets $appKey and $safeurl
        $mykey = "".$uid.$time.$appKey;
        $mydigest = md5($mykey);
    }

    // session is not initialized as we never got the post above to set session vars
    // call now the safe login to get the post to set the session vars ...

    if (!isset($_SESSION['uid']) || empty($_SESSION['uid']))
    {
        // Read the property file with the key and URL so this won't go into the main code ...
        // this sets $appKey and $safeurl
        header("Location: ".$safeurl);
    }   
    $usr = $_SESSION['uid'];  
    var_dump($usr, $_SESSION['uid']);                    
    $this->setCurrentUserName($usr);
    return TRUE;                    
}     

因此var_dump显示$ usr = NULL和$ _SESSION ['uid'],并且SSO传递了适当的员工ID。

1 个答案:

答案 0 :(得分:0)

您是否确认您的POST数据正确无误?我认为问题可能是,在没有看到周围的代码的情况下,if语句中的代码没有被执行。您需要确认已设置POST变量“digest”。或者,如果在之前if if语句设置$ _POST ['digest']和$ _POST ['uid'],那么你会发现我认为var_dump不会为null。

function User_CustomValidate($usr, $pwd) {
    session_start(); // Initialize Session data
    ob_start(); // Turn on output buffering
    $appKey = "pwssssssssssssss";
    $safeurl =  'https://safe.ssssss.com/login/sso/SSOService?app=playbooks';
    // first call back after safe login - POST is set

            $_POST['digest'] = 'test';
    $_POST['uid'] = 1234;

            if ($_POST && isset($_POST['digest'])) { 
        $digest = $_POST["digest"];

        // set the session variables ...
        $_SESSION['usernames'] = $_POST["firstname"]." ".$_POST["lastname"];
        $_SESSION['firstname'] = $_POST["firstname"];
        $_SESSION['lastname'] = $_POST["lastname"];
        $_SESSION['email'] = $_POST["email"];
        $_SESSION['uid'] = $_POST["uid"];

        // Needed for key
        $uid = $_POST["uid"];
        $time = $_POST["time"];

        // Read the property file with the key and URL so this won't go into the main code ...
        // this sets $appKey and $safeurl

        $mykey = "".$uid.$time.$appKey;
        $mydigest = md5($mykey);
    }

    // session is not initialized as we never got the post above to set session vars
    // call now the safe login to get the post to set the session vars ...

    if (!isset($_SESSION['uid']) || empty($_SESSION['uid']))
    {

        // Read the property file with the key and URL so this won't go into the main code ...
        // this sets $appKey and $safeurl

        header("Location: ".$safeurl);
    }   

    $usr = $_SESSION['uid'];  
    var_dump($usr, $_SESSION['uid']);                    
    $this->setCurrentUserName($usr);
    return TRUE;
}