Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3231796
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:05:12+00:00 2026-05-17T17:05:12+00:00

I’m using the Facebook PHP SDK (2.1.2). All I want to do is what

  • 0

I’m using the Facebook PHP SDK (2.1.2). All I want to do is what almost every Facebook application with req_perms has. The stupid “request for permissions” box to pop up when you install it.

I do not want a button that the user has to push. I do not want a popup to appear. I do not want to use FBML, since they’re doing away with it.

This is the standard Facebook permissions dialog that shows up where my application should show up in the canvas iframe.

I tried:

<?php if(!$me): ?>
    <head>
        <meta HTTP-EQUIV="REFRESH" content="0; <?php echo $loginUrl; ?>">
    </head>
<?php die(); ?>
<?php endif; ?>

That, for some reason, showed a Facebook logo linked to the correct URL I wanted (not what I want!)

<?php if($me): ?>
    window.fbAsyncInit = function() {
        FB.init({
            appId   : '<?php echo $appid; ?>',
            session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
            status  : true, // check login status
            cookie  : true, // enable cookies to allow the server to access the session
            xfbml   : true // parse XFBML
        });

        // Whenever the user logs in, we refresh the page
        FB.Event.subscribe('auth.login', function() {
            window.location.reload();
        });
    };

    (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    }());
 </script>
 <fb:redirect url="<?php echo $loginUrl; ?>" />
 <?php die("</html>"); ?>

This one showed a blank page.

<?php if($me): ?>
    window.fbAsyncInit = function() {
        FB.init({
            appId   : '<?php echo $appid; ?>',
            session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
            status  : true, // check login status
            cookie  : true, // enable cookies to allow the server to access the session
            xfbml   : true // parse XFBML
        });

        // Whenever the user logs in, we refresh the page.
        FB.Event.subscribe('auth.login', function() {
            window.location.reload();
        });
    };

    (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    }());
 </script>
 <script>
     FB.login(function(response) {
         if (response.session) {
             if (response.perms.indexOf('publish_stream') != -1) {
                 //User has logged in and given us publish_stream permissions
             );
             else {
                 //User has logged in but not given us publish_stream
             }
         }
         else {
             //User is not logged in
     }, {perms:'offline_access,publish_stream'});
 </script>

This one also shows a blank page.

What I want isn’t unpopular, but the Facebook documentation is the worst documentation I’ve ever come accross. Nothing works. Something this idiotically simple should not take two days to figure out.

Here’s the solution I ended up with:

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId   : '<?php echo $appid; ?>',
            session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
            status  : true, // check login status
            cookie  : true, // enable cookies to allow the server to access the session
            xfbml   : true     // parse XFBML
        });

        FB.getLoginStatus(function(response) {
            if (response.session) {
                // Logged in and connected user, someone you know.
            } else {
                // No user session available, redirect them to login.
                window.top.location = "<?php echo $loginUrl; ?>";
            }
        });

        // Whenever the user logs in, we refresh the page.
        FB.Event.subscribe('auth.login', function() {
            window.location.reload();
        });
    };

    (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    }());
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:05:13+00:00Added an answer on May 17, 2026 at 5:05 pm

    Basically, you use the PHP SDK to get the login URL and then do a JavaScript redirect to that URL. The example http://github.com/facebook/php-sdk/blob/master/examples/example.php does everything for you except for the redirect. In the example, they have a link you click to login. If you want it to be automatic, do the following.

    <script>
        FB.getLoginStatus(function(response) {
            if (response.session) {
                // Logged in and connected user, someone you know.
            } 
            else {
                // No user session available, redirect them to login.
                window.top.location = <?php echo $loginUrl; ?>
            }
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.