duanjianlu0506 2015-06-29 22:15
浏览 40
已采纳

当通过url字符串接收会话ID时,PHP会话变量不向前传递

Due to cross site session management, firstly I sent session id through url. Please note I had a $username variable created. First code is just a snap of a larger code.

ini_set("session.use_cookies",0);
ini_set("session.use_trans_sid",1);
session_start();
$session_id = $username;
header("location: http://somedomain.com/receive.php?session_id=". $session_id );

Now I received it here and creating a new session I have forwarded the session variable in same site:

ini_set("session.use_cookies",0);
ini_set("session.use_trans_sid",1);
session_id($_GET['session_id']);
$some_var=session_id();
session_destroy();
session_start();
$_SESSION["var_name"] = $some_var;
//echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
header("location: anotherfile.php");

When I uncomment the echo line above and comment header line, then I can see the session array successfully. But when I pass it to anotherfile.php I loose the session.

session_start();
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';

Any help why I am unable to fetch the session in last file.

  • 写回答

1条回答 默认 最新

  • douniao7308 2015-06-29 23:35
    关注

    change the second file

       <?php
            ini_set("session.use_cookies",0);
            ini_set("session.use_trans_sid",1);
            session_id($_GET['session_id']);
            $some_var = session_id(); // remove session_destroy code because no        session is set before.
            session_start();
            $_SESSION["var_name"] = $some_var;
            header("location: anotherfile.php");
    

    to this it will be fine

       <?php
    
            session_id($_GET['session_id']);
            $some_var = session_id(); // remove session_destroy code because no        session is set before.
            session_start();
            $_SESSION["var_name"] = $some_var;
            header("location: anotherfile.php");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示