Facebook PHP API login window popup

23,114

Solution 1

When the popup login box loads and the user signs in/connects, the box then loads the site with ?code=XXX appended to the url. So for the site I added a php if statement

<?php
    if (isset($_REQUEST['state']) && isset($_REQUEST['code'])) {
        echo "<script>
            window.close();
    window.opener.location.reload();
        </script>";
} else {
        // load page
    }
?>

What this does is close the popup and reload the original page that initiated the popup.

Solution 2

You should use Facebook Javascript SDK and authorize user using Javascript function FB.login(). Tutorial is here http://developers.facebook.com/docs/reference/javascript/FB.login/

Share:
23,114

Related videos on Youtube

Todd Low
Author by

Todd Low

Updated on July 23, 2022

Comments

  • Todd Low
    Todd Low almost 2 years

    I'm using using the most recent version of facebook's php api sdk. I'm trying to make the login button activate a popup instead of opening the full page. I tried using this tutorial: http://thinkdiff.net/facebook/create-facebook-popup-authentication-window-using-php-and-javascript/

    The popup worked but when I logged in, instead of the popup window closing, the website just opened inside the popup.

    Does anybody know what I need to do to make the popup window close once I have logged in?

    Here is my php code for generating the login url:

    <?php
        $loginUrl = $me_on_facebook->getLoginUrl(array(
            'display' => 'popup',
            'next' => $config['baseurl'],
            'redirect_uri' => $config['baseurl'],
            'scope' => 'email'
        ));
    ?>
    
  • Todd Low
    Todd Low over 11 years
    My whole site is based on facebook's php sdk. Wouldn't initializing the login via javascript sdk affect this?
  • Elena Sharovar
    Elena Sharovar over 11 years
    When you use Javascript SDK, you make init() with cookie:true parameter. So, Javascript SDK saves token in a cookie, and your PHP SDK then works with that cookie. Init() is described here developers.facebook.com/docs/reference/javascript - so, Javascript and PHP SDK can both work on same site, and they will share same session using cookie.

Related