【发布时间】:2015-05-11 18:55:50
【问题描述】:
我有一个名为 fbconfig.php 的文件
如果我将变量附加到 url http://localhost/fbconfig.php?amount=700 我无法检索脚本中的变量。
<?php
session_start();
$amount = $_GET['amount'];
echo $amount; // NOTHING HAPPENS
// added in v4.0.0
require_once 'autoload.php';
//require 'functions.php';
require 'dbconfig.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// Other Variables
// init app with app id and secret
FacebookSession::setDefaultApplication( '123123123','12312312' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://localhost/fbconfig.php' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$fbfirstname = $graphObject->getProperty('first_name'); // To Get Facebook full name
$fbsecondname = $graphObject->getProperty('last_name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
$_SESSION['FBFIRSTNAME'] = $fbfirstname;
$_SESSION['FBSECONDNAME'] = $fbsecondname;
//checkuser($fbid,$fbfullname,$femail,$amount,$days);
/* ---- header location after session ----*/
//header("Location: apply.php?amount=".$a."&days=".$b."");
} else {
$loginUrl = $helper->getLoginUrl();
//header("Location: ".$loginUrl);
}
echo $amount; // NOTHING HAPPENS
?>
那么任何想法为什么我不能得到变量?我尝试了很多不同的方法
谢谢
【问题讨论】:
-
确定您正在运行正确的脚本?尝试
var_dump($_GET)而不是回显一个值,以查看脚本中真正出现的内容。也许你正在进行一些重写,他们正在剥离参数。
标签: php facebook session facebook-graph-api