passing session id via url

前端 未结 5 1325
逝去的感伤
逝去的感伤 2020-12-03 23:26

I\'m trying to get my script to use url session id instead of cookies. The following page is not picking up the variable in the url as the session id. I must be missing some

相关标签:
5条回答
  • 2020-12-04 00:04

    It looks like you just need to call session_start() on the second page.

    From the docs:

    session_start() creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie.

    EDIT:

    That said, you could also try manually grabbing the session id from the query string. On the second page you'd need to do something like:

    ini_set("session.use_cookies",0);
    ini_set("session.use_trans_sid",1);
    session_id($_GET['session_id']);
    print_r($_SESSION);
    print(session_id());
    

    Note that the session_id() function will set the id if you pass it the id as a parameter.

    0 讨论(0)
  • 2020-12-04 00:06

    be careful when using the url to pass session ids, that could lead to session hijacking via the referer!

    0 讨论(0)
  • 2020-12-04 00:16

    Instead of hardcoding 'PHPSESSID', use this:

    session_id($_GET[session_name()]);
    
    0 讨论(0)
  • 2020-12-04 00:16

    My issue was using Flash in FF (as flash piggy backs IE, so sessions are not shared between the flash object and firefox)

    Using php 5.3 all these answers pointed at the truth. What I finally found to work was pretty simple.. pass the id in the query string. Set it. THEN start the session.

    session_id($_GET['PHPSESSID']);
    session_start();
    
    0 讨论(0)
  • 2020-12-04 00:19

    Just a little correction ... Don't forget to check param if it exists. This worked for me well.

    if (isset($_GET['PHPSESSID'])) {
      session_id($_GET['PHPSESSID']);
    }
    session_start();
    
    0 讨论(0)
提交回复
热议问题