<?php
/*
appinclude.php
auth: Graham McCarthy @ Ryerson University Library
date: June 28th 2007
desc: Connects facebook to the API and creates global variables
	  If Session is invalid, sends user to login page.
	
*/

require_once 'facebook.php';

//Change the keys here to your own api and secret keys:
$appapikey = 'PUT_YOUR_API_KEY_HERE';
$appsecret = 'PUT_YOUR_SECRET_KEY_HERE';
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->require_login();

//Change the following urls to your callback url and Internal Url
$appcallbackurl = 'http://www.YOURSERVER.com/APP_DIRECTORY/';  
$appInternalURL = 'http://apps.facebook.com/CANVAS_PAGE_URL/';

//catch the exception that gets thrown if the cookie has an invalid session_key in it
try {
  if (!$facebook->api_client->users_isAppAdded()) {
    $facebook->redirect($facebook->get_add_url());
  }
} catch (Exception $ex) {
  //this will clear cookies for your app and redirect them to a login prompt
  $facebook->set_user(null, null);
  $facebook->redirect($appcallbackurl);
}
?>