This document refers to an outdated version of PHP SDK. Please use the latest version.
PHP SDK Version

FacebookRedirectLoginHelper for the Facebook SDK for PHP

A helper class for getting a FacebookSession using the OAuth protocol.


If your web app uses Facebook Login on the back-end, you'll need to redirect your visitors to a URL at Facebook to initiate a login request. Facebook then redirects the user to your apps callback URL, providing session data. This helper class will generate the login URL for you, and can process and validate the data from Facebook, returning a FacebookSession on success.

This class can be extended, and the storeState($state) and loadState() methods overridden, to store the state check using another method besides the default $_SESSION.


$helper = new FacebookRedirectLoginHelper($redirect_url, $appId = NULL, $appSecret = NULL); echo '<a href="' . $helper->getLoginUrl() . '">Login with Facebook</a>';

Then, in your callback page (at the redirect url) when Facebook sends the user back:

$helper = new FacebookRedirectLoginHelper($redirect_url); try { $session = $helper->getSessionFromRedirect(); } catch(FacebookRequestException $ex) { // When Facebook returns an error } catch(\Exception $ex) { // When validation fails or other local issues } if ($session) { // Logged in. }

Instance Methods


Generates the URL to redirect a web visitor to Facebook to login to your app.


getLogoutUrl($session, $next_url)
Generates the URL to redirect a web visitor to Facebook to logout, with a url to redirect to after.


Processes the redirect data from Facebook, if present. Returns a FacebookSession or null.