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.