0

我认为这是一个语法问题,但我已经尝试了几种不同的方法。在 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。

4

1 回答 1

0

您是否验证过您的 POST 数据是否正确?我认为问题可能是,没有看到周围的代码,你的 if 语句中的代码没有被执行。您需要确认您的 POST 变量“digest”已设置。或者为了测试是否在 if 语句之前设置了 $_POST['digest'] 和 $_POST['uid'] 然后你会发现我认为 var_dump 不会为空。

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;
}
于 2013-07-03T18:04:18.833 回答