facebook login button integration

Discussion in 'PHP' started by lasserh, Aug 27, 2011.

  1. #1
    Hi all
    So I have a website to which I have added a facebook login button. the button itself works like a charm. However, I can't figure out how I can check, if the user is now logged in, so I only show the content to logged in users. Dows FB set a cookie upon loggin in, or how can I check for it?
    I also would like to pull the data about the user from facebook. i'm thinking I need to access the Graph API, but I'm not that proficient in programming, and cant seem to understand how it's done.
    Can someone please help me?
    thanks
     
    Solved! View solution.
    lasserh, Aug 27, 2011 IP
  2. Technoslab

    Technoslab Peon

    Messages:
    46
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    0
    #2
    Are you using the php SDK ?
     
    Technoslab, Aug 27, 2011 IP
  3. Technoslab

    Technoslab Peon

    Messages:
    46
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    0
    #3
    You can also check facebook's new developer forum @ facebook.stackoverflow.com
     
    Technoslab, Aug 27, 2011 IP
  4. floydcpa

    floydcpa Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hot to do this i need to get that
     
    floydcpa, Aug 27, 2011 IP
  5. lasserh

    lasserh Guest

    Messages:
    8
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for your reply
    Oddly enough, I can't seem to find any documentation about how to see, if the user has logged in. It's easy enough to implement the login button, but I need to be able to access a cookie or something. Othewise it's no use...
     
    lasserh, Aug 28, 2011 IP
  6. #6
    Here's a snippet from a fb application. For websites, procedure is same.

    Change a few things link canvasurl,fbconnect=1,canvas=0 etc.

    
    <?php
    session_start();
    ob_start();
    require_once("facebook.php"); // including the SDK
    $thispage = 'http://example.com/myfbAPP/index.php';
    $canvasurl = 'http://apps.facebook.com/myfbAPP/';
    $fb = new Facebook(array('appId'  => 'APP_ID','secret' => 'APP_SECRET','cookie' => true,));
    $perms = 'publish_stream,user_photos';
    $user = $fb->getUser();
    if(is_null($user)  || $user==0){
       $loginurl = $fb->getLoginUrl(array('canvas'=>1,'fbconnect'=>0,'display'=>'page','redirect_uri'=>$canvasurl,'scope'=>$perms));
       echo"<script type='text/javascript'>top.location=\"$loginurl\";</script>";
       exit;
    }
    else{
        $userinfo = $fb->api("/$user");
        echo"
        <br />
        <img src='http://graph.facebook.com/$user/picture/?type=square' alt='' />
        <a class='fbxWelcomeBoxName' href='$userinfo[link]'>$userinfo[name]</a>
        <br/>
        ";
    
    
    // YOUR POST LOGIN STUFF GOES HERE 
    ?>
    
    Code (markup):
     
    Technoslab, Aug 28, 2011 IP
  7. lasserh

    lasserh Guest

    Messages:
    8
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Got it working now.
    Thanks to Technoslab. It got me on the right track.
     
    lasserh, Aug 28, 2011 IP