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

FacebookJavaScriptLoginHelper

A helper class for getting a FacebookSession using the session from the Facebook SDK for JavaScript.

Usage

If your web app uses the Facebook SDK for JavaScript, you can access that in your PHP code as well. This helper class will process and validate the cookie data used by the Facebook SDK for JavaScript, returning a FacebookSession on success.

Example:

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

It's important to note that on first access, or if a session has since expired, these methods will operate on data that is one request-cycle stale. You will likely want to make an Ajax request when the login state changes in the Facebook SDK for JavaScript. Information about that here: FB.event.subscribe.

Instance Methods

getSession

getSession()
Processes the data available from the Facebook SDK for JavaScript, if present. Returns a FacebookSession or null.