简体   繁体   中英

Session is disappearing

I am using Abraham William's Twitter oAuth library.

Following is my code:

if (isset($_REQUEST['oauth_token'])){
  print_r($_SESSION);
  exit;
}
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);     
/* Get temporary credentials. */
$request_token = $connection->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
  case 200:
    /* Build authorize URL and redirect user to Twitter. */
    $url = $connection->getAuthorizeURL($token);
    print "<script>self.location='$url';</script>";
    break;
  default:
    /* Show notification if something went wrong. */
    echo 'Could not connect to Twitter. Refresh the page or try again later.';
    return;
}

If I check for the $_SESSION right before the redirect, $_SESSION is there. When the redirect occurs, $_REQUEST['oauth_token'] is set (I verified this), but the $_SESSION no longer exists.

My browser is set to accept cookies and third party cookies. Any ideas?

You don't have session_start(); at the top of your page. session_start() is required BEFORE your code uses any session variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM