1

When a user attempts to login to my website using their facebook account, I am trying to redirect to a script that checks the users id against my db to see if they have registered. When I click login it brings up a facebook page to login using fb credentials but then just redirects to the home page of mywebsite rather than running the script that checks the user against the database.

This is the code on my home page where I attempt to login.

<?php require '.../src/facebook.php'; $facebook = new Facebook(array( 'appId' => 'APP_ID', 'secret' => 'SECRET', 'cookie' => true, )); //2. retrieving session $session = $facebook->getUser(); //3. requesting 'me' to API $me = null; if ($session) { try { $uid = $facebook->getUser(); $me = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); } } //4. login or logout if ($me) { $logoutUrl = $facebook->getLogoutUrl(array( 'next'=>'http://.../logout.php' )); } else { $loginUrl = $facebook->getLoginUrl(array( 'next'=>'http://.../checkFBLogin.php' )); } ?> 

Futher down:

<?php if ($me): ?> <a href="<?php echo $logoutUrl; ?>">Logout with Facebook</a> <?php else: ?> <a href="<?php echo $loginUrl; ?>">Login with Facebook</a> <?php endif ?> 

It would also be helpful to know if there is a way to check against my database before logging into Facebook to check if they are registered to my website.

1 Answer 1

1

The name of the key in the array is not next its redirect_url.

$loginUrl = $facebook->getLoginUrl(array( 'redirect_url'=>'http://.../checkFBLogin.php' )); 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, however it still appears that neither getloginurl or getlogouturl are redirecting to their pages.
Is it just redirecting to the facebook home page? Is the URL correct?
It is redirecting me to my home page. And yeah i've used the correct absolute url
Ok, might be something in your checkFBLogin or maybe the URL you defined in the app settings is wrong

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.