<?php
include_once 'facebook.php';

$appapikey = 'ad4ccedf62d21a09bf140d1533102b20';
$appsecret = 'e50eb37bc884d73f37f66918e5856564';
$facebook = new Facebook($appapikey, $appsecret);
$url = 'http://www.library.uiuc.edu/ugl/facebook/info.php';
//$facebook->api_client->profile_setFBML($fbml=null, $uid=null);

$user = $facebook->require_login();
$facebook->api_client->fbml_refreshRefUrl($url);
$fbml = '<fb:ref url=' . $url . ' />';
$facebook->api_client->profile_setFBML($fbml, $user);


//[todo: change the following url to your callback url]
$appcallbackurl = 'http://www.library.uiuc.edu/ugl/facebook/';  

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

// weak php 4 substitute for try catch code above

    if (!$facebook->api_client->users_isAppAdded()) {
    	if (!$facebook->redirect($facebook->get_add_url())) {
			
		  //this will clear cookies for your application and redirect them to a login prompt
		  $facebook->set_user(null, null);
		  $facebook->redirect($appcallbackurl);    
    	} 
	}






?>

