I am migrating my old FB app to the new graph API using the PHP API
I have two pages: public ones (which require no user login) and private ones (which do)
So the code of every single php page in my application works as follows:
if (this_page_requires_user_login){
$facebook = new Facebook(...) ;
$session = $facebook->getSession ;
if (!$session){
$url =$facebook.getLoginUrl(array(next => current_page );
echo "<fb:redirect url=$url/>" ;
}
// the rest of the code continues here
Now as you can see, this way of working forwards every single page to the login url and while it works, it is also slow and appends the &session={bla} string to very single url.
I need a way to check where a user is already logged in before I redirect him to loginpage. But i can not find such method in the php api. What's the best way to do this?
EDIT
This seemed to do the trick
if ($session) {
try {
$me = $facebook->api('/me');
if ($me) {
// here comes your code for user who is logged in
}
} catch (FacebookApiException $e) {
login()
}
}else{
login()
}
function login(){
$url =$facebook.getLoginUrl(array(next => current_page );
echo "<fb:redirect url=$url/>" ;
}