繁体   English   中英

使用Facebook网站登录后重定向页面

[英]Redirect page after site login with facebook

我在使用Facebook登录网站后遇到重定向页面的问题。
1.单击网站上的Facebook登录按钮后,它将重定向到Facebook登录页面
2.用户获得身份验证,但不会重定向到headrer('');给出的headrer('');
3.如果我刷新同一页面,则它将重定向到给定的位置,并且URL看起来像=“> http://192.1.1.1/mysite/welcome.php/# =
4.它适用于google.com,但不适用于本地网址,并且Google网址看起来像不正确的Google网址我的代码

if(isset($_GET['fb']))
{
   $token_url = "https://graph.facebook.com/oauth/access_token?"."client_id=".$config['App_ID']."&redirect_uri=".urlencode($config['callback_url'])."&client_secret=".$config['App_Secret']."&code=".$_GET['code'];   
   $response = file_get_contents($token_url); 
   $params = null;
   parse_str($response, $params);

   $graph_url = "https://graph.facebook.com/me?access_token=".$params['access_token'];
   $user = json_decode(file_get_contents($graph_url));  //user data from facebook

   $email = $user->{'email'};    //i am getting email id from json data

   //search out for entry available for email in database
   $val_user = "SELECT email FROM tbl_facebook WHERE email ='".$email."'";
   $res_val_user = $con->query($val_user);
   $count = mysqli_num_rows($res_val_user);
   // if not then insert data to database
   if($count==0)
   {
       $ins_fb = "INSERT INTO tbl_facebook set email='".$email."'";
       $res_fb = mysqli_query($con,$ins_fb);
       if($res_fb)
       {
          //echo "facebook data saved"; exit; //working for this   
          //header('Location:https://www.google.co.in/'); //working for this also
          header('Location:http://192.1.1.1/mysite/welcome.php');
       }
       else
       {
          echo "facebook data is not saved";
       }
   }
   else // if yes then redirect to welcome page
   {
        //echo "login successfully"; exit; // working for this also 
        header('Location:http://192.1.1.1/mysite/welcome.php');  // getting problem to redirect
        //header('Location:https://www.google.co.in/'); 
   } 
}



<?php
  // code for facebook login

 require 'lib/facebook/src/config.php';
 require 'lib/facebook/src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
      'appId'  => $config['App_ID'],
      'secret' => $config['App_Secret'],
      'cookie' => true
));
?>



<a class="btn-facebook" href="https://www.facebook.com/dialog/oauth?client_id=<?php echo $config['App_ID']?>&redirect_uri=<?php echo $config['callback_url']?>&scope=email,user_likes,publish_stream">
                    <i class="icon-facebook icon-large"></i>
                    Signin with Facebook
                </a>

标头重定向问题通常是在PHP关闭标记后或开始标记前,输出标头()之前有空白时等。

为了避免这种情况,我们需要确保

  • 没有提到的空白
  • 在此之前,请勿回声。

另外,即使header()不起作用,也可以添加exit()作为

header('Location:http://192.1.1.1/mysite/welcome.php');
exit();

最后,您可以使用JS作为

echo '<script>window.location = "'.$url.'";</script>';
exit;

希望这可以帮助 :)

只使用本地路径URL,不使用完整URL

header("Location: welcome.php");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM