douaonong7807 2011-12-03 09:30
浏览 117

从其他网站重定向时,会话变量丢失

I use OAuth to authenticate at an external website. Everything is okay but the session variable misses after redirecting from external websites.

Summary: I store a session var in my website then go to login page of other website. After logging in and confirming, it redirects to my callback, when I check the previous session var, it misses! How to fix it?

I tried to call session_start() everywhere I use session but it doesn't work. Of course I enabled session in "php.ini" and enabled cookie in browser. :) I debugged but can't find the reason out.

enter image description here

Update: After storing my session var, I do a request like this: http://mixi.jp/connect_authorize.pl?oauth_callback=http%3A%2F%2Fmypage.com%2Fcallback.php&oauth_token=fjdklsfjlksd

Note the oauth_callback, it is the redirect URL. I don't know what mixi.jp use to redirect.

  • 写回答

2条回答 默认 最新

  • duanchao4445 2011-12-03 09:49
    关注

    The session id is stored in a cookie. The cookie is send in every page of the domain you registered in. Whe you jump to another domain, your cookie with the session id is not send. You must pass the session id to your new domain and then create a new cookie in this domain with the session id.

    header('Location:redirect.php?session=' . session­_id());
    

    And then in the redirected page restore the session

    <?php
      session_id($_GET['session']);
      session_start(); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序