0

问题:重定向后会话变量不保留。

facebook.php(创建并存储会话变量)

按钮指向 available.php --> search.php

我正在使用标头重定向。所以 $_SESSION['seshfbId'] 在 available.php 上回显,但不在 search.php 上

代码

脸书.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); 
?>

可用的.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']); 
?>

搜索.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;
4

1 回答 1

0

解决。因为我怀疑 opentok API 与我的 sesh 变量发生冲突,因为它调用了会话变量。我将所有会话变量移至一个 php 并解决了问题。

于 2013-05-10T15:57:47.577 回答