Take the 2-minute tour ×

I want to make the height of a layer dependent of the fact if the user is logged into Facebook or not. I've tried to see if a user is logged in to Facebook using their cookie but this didn't work.

height: <?php if($_COOKIE["c_user"]){echo "100px;";} else{ echo "50px;";} ?>

Most solutions I found were speaking about apps within Facebook but this is not what I'm searching for. My website just only needs a hight which is dependent the user is logged into Facebook or not...

share|improve this question
If you're talking about whether the user is logged into Facebook independent of Facebook login to your site, this is not possible. Otherwise, @ShaneCurran's answer should help. (Although he references the JS API, you can do something similar in PHP as well.) –  Michael Mior Nov 3 '12 at 20:23
add comment

2 Answers

Facebook's API has a function for this: https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

It would return JSON containing a "status" paramater. If status is equal to "connected" it means they are logged in. If the status is "unknown" it means they aren't logged in.

share|improve this answer
But that's only for an app... And I'm not making an app! –  Julian Gommers Nov 3 '12 at 20:31
@JulianGommers Then you can't get this information. Imagine if any website could check if you were logged in to any other site, say your bank? –  Michael Mior Nov 3 '12 at 20:50
add comment

You can actually know if the user is logged-in to Facebook by using the FB.getLoginStatus() method of the JS SDK (but it would require an app, of course).

Even without asking the user to allow any app, Facebook would reveal if the user is actually logged-in to Facebook by returning not_authorized response to the above method.


<!doctype html>
<title>JS SDK Test</title>
  window.fbAsyncInit = function() {
      appId      : 'YOUR_APP_ID', // App ID from the App Dashboard
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
      xfbml      : true  // parse XFBML tags on this page?

    FB.getLoginStatus(function(response) {
        if( response.status == 'connected' || response.status == 'not_authorized' ) {
            // user is logged-in to Facebook

  // Load the SDK Asynchronously
(function(d, debug){
    if (d.getElementById(id)) {return;}
    ref.parentNode.insertBefore(js, ref);
share|improve this answer
add comment

Your Answer


