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

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.

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(); 

Make sure your site's domain is 100% identical before and after the redirection.

Note that

www.yoursite.com 

and

yoursite.com

are two different sites cookie-wise.