我有一个用户系统,我在其中存储用户 ID,$_SESSION['uid']
用户可以浏览他的帐户设置,但是我最近添加了链接您的 Twitter 帐户的功能......这就是它变得奇怪的地方。
我有一个这样的推特请求页面:
session_start();
require("twitteroauth/twitteroauth.php");
// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('***', '***');
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://livepierced.com/reg_twit.php');
// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
// If everything goes well..
if($twitteroauth->http_code==200){
// Let's generate the URL and redirect
$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
//var_dump($url);
header('Location: '. $url);
} else {
// It's a bad idea to kill the script, but we've got to know when there's an error.
//die('Something wrong happened.');
}
此时我可以 var 转储会话,并获取UID
、AuthToken
和AuthTokenSecret
但是,一旦我在 Twitter 端单击了授权,我就会被发送回此页面:
session_start();
require("twitteroauth/twitteroauth.php");
if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){
// We've got everything we need
echo "<h1>TOKEN GOOD BRO!</h1>";
} else {
// Something's missing, go back to square 1
//var_dump($_REQUEST);
//header('Location: req_twit.php');
}
但是,现在我的会话已经被销毁,或者已经开始一个新会话,因为 var 转储 $_SESSION 只会给我一个会话 ID