0

I am getting problem to redirect page after website login with facebook.
1. On click of facebook login button from site it redirect to facebook login page
2. User get authenticate but it is not redirecting to next page given in headrer('');
3. If i refresh same page then it redirect to given location and url is looking like =">http://192.1.1.1/mysite/welcome.php/#=
4. It is working properly for google.com but not for local url and google url is looking like incorrect google url My code

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> 
7
  • can u post the login script that u are using ? Commented Jan 14, 2014 at 10:05
  • login functionality working fine and i am getting user data from facebook but getting problem while redirecting Commented Jan 14, 2014 at 10:16
  • So its coming inside if(isset($_GET['fb'])){} and able to get the user data but header('Location:192.1.1.1/mysite/welcome.php'); does not work ? Commented Jan 14, 2014 at 10:20
  • yes if i write echo "something"; exit; then it show "something" but it is not redirecting header location Commented Jan 14, 2014 at 10:23
  • often its an issue of white space after php close tag, and echo somewhere. But to avoid that you can use JS redirect echo '<script>window.location = "'.$url.'";</script>'; Commented Jan 14, 2014 at 10:29

2 Answers 2

1

Header redirect issues are often when there is a white space after the PHP close tag or before start tag, output before the header() etc.

To avoid this we need to make sure

  • There is no white space as mentioned
  • Do not echo anything before this.

In addition even if the header() does not work then add an exit() as

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

and finally you can use JS as

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

Hope this helps :)

Sign up to request clarification or add additional context in comments.

Comments

0

Just use local path url do not use full URL

header("Location: welcome.php"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.