问题:会话变量在重定向后不保留
facebook.php(创建并存储会话变量)
按钮指向available.php -> searching.php
我正在使用头重定向。因此$_SESSION['seshfbId']在available.php上返回,但不搜索。php
代码facebook.php
<?php
session_start(); // start up your PHP session!
header( 'Location: http://www.redacted.co/chat.php' ) ;
function createSeshVariables($name, $email, $college, $photo, $id)
{
// set the value of the session variable 'name'
$_SESSION['seshName'] = $name;
// set the value of the session variable 'email'
$_SESSION['seshEmail'] = $email;
// set the value of the session variable 'education'
$_SESSION['seshEducation'] = $college;
// set the value of the session variable 'photolink'
$_SESSION['seshPhotolink'] = $photo;
// set the value of the session variable 'photolink'
$_SESSION['seshfbId'] = $id;
}
createSeshVariables($fbName,$fbEmail,$fbCollege,$photolink,$fbId);
?>
available.php
<?php
session_start(); // start up your PHP session!
header( 'Location: http://www.redacted.co/assets/php/searching.php' );
echo $_SESSION['seshfbId'];
//if i comment out header redirect the echo works here.
changeStatusToAvailable($_SESSION['seshfbId']);
?>
searching.php
<?php
session_start(); // start up your PHP session!
echo $_SESSION['seshfbId'];
?>
编辑:在vardump之后,我在搜索页面上找到了seshId和seshToken。但是用于创建它的代码在tac.php中。我有一种感觉tac.php代码与之前的会话变量冲突
tac.php
$apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET);
$session = $apiObj->createSession( $_SERVER["REMOTE_ADDR"], array(SessionPropertyConstants::P2P_PREFERENCE=> "enabled") );
$seshId = $session->getSessionId();
$_SESSION['seshId'] = $seshId;
$token = $apiObj->generate_token($seshId, RoleConstants::PUBLISHER, null);
$_SESSION['seshToken'] = $token;
已解析。因为我怀疑opentok API与我的会话变量发生冲突,因为它调用了会话变量。我把所有的会话变量移到一个PHP中,问题就解决了。