Php $\u会话变量未携带到其他页面

Php $\u会话变量未携带到其他页面,php,session,Php,Session,这是我的第一页。$\u会话变量工作正常。在进行var转储时,它具有我需要的信息 <?php // Start a session. This is necessary to hold on to a few keys the callback script will also need session_start(); // Include the TumblrOAuth library require_once('tumblroauth/tumblroauth.php'); //

这是我的第一页。$\u会话变量工作正常。在进行var转储时,它具有我需要的信息

<?php
// Start a session.  This is necessary to hold on to  a few keys the callback script will also need
session_start();

// Include the TumblrOAuth library
require_once('tumblroauth/tumblroauth.php');

// Define the needed keys
$consumer_key = "";
$consumer_secret = "";

// The callback URL is the script that gets called after the user authenticates with tumblr
$callback_url = "http://tumblrstats.sytes.net/info/chooseBlog.php";

// Let's begin.  First we need a Request Token.  The request token is required to send the user
// to Tumblr's login page.

// Create a new instance of the TumblrOAuth library.  For this step, all we need to give the library is our
// Consumer Key and Consumer Secret
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret);

// Ask Tumblr for a Request Token.  Specify the Callback URL here too (although this should be optional)
$request_token = $tum_oauth->getRequestToken($callback_url);

// Store the request token and Request Token Secret as out chooseBlog.php script will need this
$_SESSION['request_token'] = $token = $request_token['oauth_token'];
$_SESSION['request_token_secret'] = $request_token['oauth_token_secret'];

// Check the HTTP Code.  It should be a 200 (OK), if it's anything else then something didn't work.
switch ($tum_oauth->http_code) {
  case 200:
    // Ask Tumblr to give us a special address to their login page
    $url = $tum_oauth->getAuthorizeURL($token);

    // Redirect the user to the login URL given to us by Tumblr
    header('Location: ' . $url);


    break;
default:
    // Give an error message
    echo 'Could not connect to Tumblr. Refresh the page or try again later.';
}
exit();
?>

这第二页就是它被打断的地方。$\u会话变量上的var dump没有提供任何信息,因此在尝试访问它时,我会得到一个未定义的索引错误

<?php
//Load library
session_start();
require_once('auth/tumblroauth/tumblroauth.php');
require_once('../tumblr/lib/Tumblr/API/Client.php');
include('functions.php');
include('blogClass.php');

// Define the needed keys
$consumerKey = "";
$consumerSecret = "";

// Create instance of TumblrOAuth. Give consumer key and secret.
$tumblrOAuth = new TumblrOAuth($consumerKey, $consumerSecret, $_SESSION['request_token'], $_SESSION['request_token_secret']);

//Retrieve an Access Token.
$accessToken = $tumblrOAuth->getAccessToken($_REQUEST['oauth_verifier']);

// Remove Request Token and Secret
unset($_SESSION['request_token']);
unset($_SESSION['request_token_secret']);

// Make sure nothing went wrong.
if (200 == $tumblrOAuth->http_code)
{
  //Everything is good
}
else
{
    die('Unable to authenticate');
}

//Present our variable more cleanly
$token       = $accessToken['oauth_token'];
$tokenSecret = $accessToken['oauth_token_secret'];

//Create a new instance of our client
$tumblrClient = new \Tumblr\API\Client($consumerKey, $consumerSecret);
$tumblrClient->setToken($token, $tokenSecret);

//Convert stdObject to Array
$userInfo = objectToArray($tumblrClient->getUserInfo());

//User Data
$userName = $userInfo['user']['name'];
$userLikeNum = $userInfo['user']['likes'];
$userFollowingNum = $userInfo['user']['following'];
$userDefPostFormat = $userInfo['user']['default_post_format'];

//General Individual Blog List
$blogNameList = array();
$blogNameID = array();
$blogID = 0;
foreach ($tumblrClient->getUserInfo()->user->blogs as $blog)
{
    $blogNameString = $blog->name;
    //Without ID
    $blogNameList[] = $blogNameString;
    //WithID
    $blogNameID[] = $blogNameString;
    $blogNameID[$blogNameString] = $blogID;
    //Add 1 to Blog ID
    $blogID++;
}
?>

<html lang="en-US">
<head>
    <title>Your Tumblr Stats</title>
    <link rel="stylesheet" type="text/css" href="../css/style.css">
</head>
<body>
<div id="chooseBlog">
    <?php
        foreach($blogNameList as $value)
        {
            $imgUrl = objectToArray($tumblrClient->getBlogAvatar($value, 128));
            echo "<div id='$value' class='blogSelector'><img src=$imgUrl><div id='innerContainer' class='blogInfo'><a href='http://www.$value.tumblr.com' id='info'>$value.tumblr.com</a></div></div>";
        }
    ?>
</div>
</body>
</html>

你的Tumblr统计数据

第一个页面(第一个文件)和最后一个文件(第二个文件)之间的所有页面必须具有
session\u start()
,否则将丢失PHP会话


第一个页面是否访问第二个页面?

您的两个页面是否位于同一个域中?听起来您的会话cookie没有被发送到第二个页面。它们在同一个域上。第一个页面重定向到Tumblr验证,然后使用回调url重定向到第二个页面。我以前用过这个,但经过一些修改后它坏了,我不知道我做了什么。