duanjianlu0506 2015-06-29 14: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 15: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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部