2013-07-03 65 views
0

我在想这是一个语法问题,但我尝试了几种不同的方法。运行在IIS 6上的PHP 5.4.16(这些不是我的选择)。为什么我的变量不是用SESSION变量设置的?

我无法将$ 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。

+0

有一个会议开始......你在暗示什么? – blankip

+0

找到它要去的地方MIA – Prix

+0

编辑帖子。 session_id()语句与问题无关。 – blankip

回答

0

您是否验证过您的POST数据是正确的?我认为这个问题可能是,没有看到周围的代码,你的if语句中的代码没有被执行。您需要确认您的POST变量“digest”已设置。或者为了测试,如果在设置$ _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; 
} 
+0

因此,如果$ _POST ['uid']为NULL,那么你说我正在将SESSION ['uid']变成NULL?我可以看到这个,但我不明白为什么当我回声$ _SESSION ['uid'],然后我得到员工uid信息... – blankip

+0

我猜如果是这样的话,当我回声$ _SESSION数据,那么它是从实际会话读取而不是代码? – blankip

+0

如果$ _POST ['uid']为空,那么您的代码会将用户重定向到第二个if语句中的安全url。您还必须确保设置了$ _POST ['digets'],它允许代码输入第一个if语句并设置$ _SESSION ['uid'] –