Session disappearing


#1

I am using Abraham’s Williams’ oAuth library. Here’s my code:

/* 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'];
create_session_params ();
//print_structure($connection);
//exit;
/* 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. */
    $str = 'Could not connect to Twitter. Refresh the page or try again later.';
    print "<script>alert('$str')</script>";
    return;
}

When the code executes, I get the Twitter screen asking if I approve, I click OK, and then the next chunk of code, which starts with:

if (isset($_REQUEST['oauth_token'])){
  print_structure($_SESSION);
  echo "and now the request";
  print_structure($_REQUEST);
  exit;

  if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
    $_SESSION['oauth_status'] = 'oldtoken';
      session_start();
      session_destroy();
      if ($connection) {
          unset ($connection);
      }
      print "<script>self.location='$startUrl';</script>";
  } 

will start executing as $_REQUEST[‘oauth_token’] is properly set, but then I’m diverted to the $startUrl. It turns out the $_SESSION is gone. I verified this by including some code to print the session out. It’s blank. Any idea what’s going on?


#2

note that this piece of code:

if (isset($_REQUEST[‘oauth_token’])){
print_structure($_SESSION);
echo “and now the request”;
print_structure($_REQUEST);
exit;

is what I used to test for the presence of $_SESSION, but it’s not there when I run the actual code.


#3

I am currently facing the same problem .Please let me know if you found any solution to this issue??