Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook PHP API login window popup

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'
    ));
?>
like image 357
Todd Low Avatar asked Oct 23 '12 15:10

Todd Low


2 Answers

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.

like image 107
Todd Low Avatar answered Sep 29 '22 00:09

Todd Low


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/

like image 31
Elena Sharovar Avatar answered Sep 29 '22 00:09

Elena Sharovar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!