Question:

In many samples of the PHP SDKs, the code checks for $fbme for a valid session. My question is, when there is no valid session exists, what should I do?

 

 

 

Answer:

Appreciate if you can like this page if you find it useful! - Click "Like"

When there is no valid session exists, you have to redirect the user to the Facebook login page. This can be done by using the <fb:redirect> tag.

Sample code (based on the PHP SDK) is shown below.

if (!$fbme) { 
$loginUrl = $facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0, 'next' => $canvas_base_url . 'myapp_main.php', 'cancel_url' => $canvas_base_url . 'no_login_required.php' )); echo '<fb:redirect url="' . $loginUrl . '" />';
}
  • the 'next' param is the URL where the user will be redirected to after successful login.
  • the 'cancel_url' is the URL where the user will be redirected to when he cancels the login. This can be a "about / welcome" page which is just a basic page with no login required.

 

 

 

Find my FAQ on Facebook Development useful? Download the PDF for all the FAQs HERE!