tags:

views:

370

answers:

0

I'm not sure if the php server side Facebook library validates sessions on load. So then I want to know if there is a best practice for insuring that I really do have a valid FB session and not some crackers altered $_COOKIE data.

$fb = new Facebook();

if( $fb->session_expires !== 0 && $fb->session_expires < time() ) {
 die('bad and/or old session');
}

or is it better to test the users FB id?

$fb = new Facebook();

if( $fb->user ) {
 die('no Facebook User Id given');
}

EDIT: Ok, according to facebook "Your client library should perform all the necessary validation for you" by using the application secret to md5 all the params and validate the hash. So if you have a session - it is a valid FB generated one (although it can still be expired).

Suppose that you login to a connect app. Then you logout of FB. If you load another page on that connect app then there has not been any chance for the FB JS to change the cookies to state that you are actually logged out. And since the PHP library doesn't actually call FB to validate your session it also can't know to remove the bad values.

The result is that you have a valid set of cookies sent from FB that are no longer any good. So should you try to call an API method that requires a session then your app will throw a fatal error.