views:

166

answers:

3

Ive been working with the twitter oauth and api and im having a weird issue.

What im doing is generating a request link, saving the request token and secret in a session variable, then when the user comes back from twitter, trying to retrieve those keys to store them in the database.

When i execute the following:

session_start();
$to = new TwitterOAuth($consumerkey, $consumersecret);
$tok = $to->getRequestToken();
$request_link = $to->getAuthorizeURL($tok);
$_SESSION["oauth_request_token"] = $token = $tok['oauth_token'];
$_SESSION["oauth_request_token_secret"] = $tok['oauth_token_secret'];
print_r($_SESSION)."<br>";

It displays that the session array contains my values and they are correct, however when it comes back from twitter, print_r'ing the session array produces nothing, same for echo. Its like its not there or something.

I am starting the session on both pages at the top first line.

The second page reads:

session_start();
echo $_SESSION["oauth_request_token"];
echo $_SESSION["oauth_request_token_secret"];

Weird thing is that if i manually declare the session variable on the second page, it works fine. Am i missing something?

+1  A: 

It seems, PHP doesn't save sessions correctly. Can you show phpinfo()? May be session save handler is overriden. Also, try to get rid of Twitter and experiment in pure PHP with session variables. Will this work?

FractalizeR
+1  A: 

Is the cookie with the session ID in it being set properly? If not then the session ID will be passed around in the URL so you'd have to make sure you sent it to Twitter properly.

Greg
A: 

Turns out sessions are specific to the address.

I was sending my request from

http://website.com

and it was coming back to

http://www.website.com
Patrick