如何在Facebook登录重定向后清除URL。。PHP

如何在Facebook登录重定向后清除URL。。PHP,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我正在我的页面上创建一个用户登录,可以选择使用facebook使用PHPSDK登录。我遇到的问题是facebook离开了我的网站,获得了用户和facebook的许可,然后又回到了我的网站。一切正常,但facebook创建的令牌存储在url中,据美国《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法第三季度的《基本法》第三季度的《基本法第三季度的《基本法第三季度的《基本法》第三季度

我正在我的页面上创建一个用户登录,可以选择使用facebook使用PHPSDK登录。我遇到的问题是facebook离开了我的网站,获得了用户和facebook的许可,然后又回到了我的网站。一切正常,但facebook创建的令牌存储在url中,据美国《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法》第三季度的《基本法第三季度的《基本法》第三季度的《基本法第三季度的《基本法第三季度的《基本法》第三季度的基本法第三季度的《基本法第三季度的基本法第三季度的基基本本法是是,但,但的基本本本本法第三季度的基本本本法第三季度的《基本法第三季度的基本法第三季度的基本本本本本法是,但的基基本法第三季度的基本本法是,但的基基本本本法是,但的基本本本本本本法第三季度的基本本法是,但,5659508109f2207707c8#=

如果用户在被重定向后刷新该页面,那么它会把整个事情搞砸,因为它会再次提交令牌,从而抛出php facebook错误并结束代码链

我的代码如下

//1.Use app id,secret and redirect url
 $app_id = '###################';
 $app_secret = '#########';
 $redirect_url='http://#####account/register.php';

 //2.Initialize application, create helper object and get fb sess
 FacebookSession::setDefaultApplication($app_id,$app_secret);
 $helper = new FacebookRedirectLoginHelper($redirect_url);
 $sess = $helper->getSessionFromRedirect();

     //check if facebook session exists
if(isset($_SESSION['fb_token'])){
    $sess = new FacebookSession($_SESSION['fb_token']);
}
    //logout
$logout = 'http:/########/includes/fblogin/lib/Facebook/FbLogout.php';
//3. if fb sess exists echo name 
    if(isset($sess)){
                //store the token in the php session
    $_SESSION['fb_token']=$sess->getToken();
        //create request object,execute and capture response
    $request = new FacebookRequest($sess, 'GET', '/me');
    // from response get graph object
    $response = $request->execute();
    $graph = $response->getGraphObject(GraphUser::className());
    $name = $graph->getName();
    $id = $graph->getId();
    $image = 'https://graph.facebook.com/'.$id.'/picture';
    $email = $graph->getProperty('email');
    echo "hi $name <br>";
    echo "your email is $email <br><Br>";
    echo "<img style='width: 50px; border-radius: 4px;' src='$image' /><br><br>";
    echo "<a href='".$logout."'>Logout</a>";
}else{
    //else echo login
    echo '<a href='.$helper->getLoginUrl().'>Login with facebook</a>';
}
//1.使用应用程序id、密码和重定向url
$app#id=''''''.'####################';
$app#u secret=“##########”;
$redirect_url='http://######account/register.php';
//2.初始化应用程序,创建帮助对象并获取fb sess
FacebookSession::setDefaultApplication($app\u id,$app\u secret);
$helper=newfacebookRedirectLoginHelper($redirect\uURL);
$sess=$helper->getSessionFromRedirect();
//检查facebook会话是否存在
如果(isset($\ U会话['fb\ U令牌])){
$sess=新FacebookSession($_会话['fb_令牌]);
}
//注销
$logout='http:/#########/includes/fblogin/lib/Facebook/FbLogout.php';
//3. 如果fb sess存在,则返回名称
如果(isset($sess)){
//将令牌存储在php会话中
$\u会话['fb\u令牌]=$sess->getToken();
//创建请求对象、执行和捕获响应
$request=newfacebookrequest($sess,'GET','/me');
//从响应获取图形对象
$response=$request->execute();
$graph=$response->getGraphObject(GraphUser::className());
$name=$graph->getName();
$id=$graph->getId();
$image='1https://graph.facebook.com/“.$id./图片”;
$email=$graph->getProperty('email');
回显“hi$name
”; echo“您的电子邮件是$email

”; 回声“

”; 回声“; }否则{ //else-echo登录 回声'; }

那么,如何在从facebook返回时将请求令牌存储在$sess变量中,然后清除url,以便用户无法使用url中的字符串刷新?

明白了!!简单的PHP解决方案

 if (!empty($_GET)){
    $_SESSION['got'] = $_GET;
    header("Location: http://##############/account/register.php");
}
else{
    if (!empty($_SESSION['got'])){
        $_GET = $_SESSION['got'];
        unset($_SESSION['got']);
    }