Skip to content Skip to sidebar Skip to footer

Auto Login With PHP Facebook Connect + JS

since all the changes facebook made in the past year lot of things are changed. there are some solutions over the web but they do not work any more. (LIKE THIS ONE: Using the PHP o

Solution 1:

the problem is that the php user check $user = $facebook->getUser(); doesn't recognized facebook session

Well of course it can’t – because server-side it can only access the cookies set for your domain. But Facebook can not set a cookie for your domain without the user being on that domain and interacting with Facebook.

and I think that maybe I can trigger it with JS.

Just embed the JavaScript SDK, initialize it and set the cookie: true parameter. That will make the JS SDK set a cookie under your domain, which PHP can read on the next request.

If you want to recognize a returning user “immediately”, then you would have to check client-side for this, and reload your page once when the appropriate conditions are met: JS SDK recognized returning user (FB.getLoginStatus), but PHP did not recognize him yet (have your PHP code set a variable/flag, that your JS can evaluate) – then reload page via JS, so that PHP can read the cookie that was just set by the client-side JS.


Solution 2:

Are you performing proper:

$facebook = new Facebook(array(
    'appId'  => $app_id,
    'secret' => $app_secret,
    'cookie' => true
));

before calling this method? Are you using same domain?


Post a Comment for "Auto Login With PHP Facebook Connect + JS"