[英]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.