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

  • SEARCH
  • Home
  • 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 6381923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:27:24+00:00 2026-05-25T02:27:24+00:00

I would need a persistent login on my site where I am using FB

  • 0

I would need a persistent login on my site where I am using FB Connect to log in via FB. I use PHP SDK 3. Is there any way how to make persistent login? I think, that I will have to combine PHP SDK and JS SDK, but I have no idea how to do it.

  • 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-25T02:27:25+00:00Added an answer on May 25, 2026 at 2:27 am

    The PHP-SDK example file with_js_sdk.php provides a good start for you:

    <?php
    
    require '../src/facebook.php';
    
    $facebook = new Facebook(array(
      'appId'  => '191149314281714',
      'secret' => '73b67bf1c825fa47efae70a46c18906b',
    ));
    
    // See if there is a user from a cookie
    $user = $facebook->getUser();
    
    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
      } catch (FacebookApiException $e) {
        echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
        $user = null;
      }
    }
    
    ?>
    <!DOCTYPE html>
    <html xmlns:fb="http://www.facebook.com/2008/fbml">
      <body>
        <?php if ($user) { ?>
          Your user profile is
          <pre>
            <?php print htmlspecialchars(print_r($user_profile, true)) ?>
          </pre>
        <?php } else { ?>
          <fb:login-button></fb:login-button>
        <?php } ?>
        <div id="fb-root"></div>
        <script>
          window.fbAsyncInit = function() {
            FB.init({
              appId: '<?php echo $facebook->getAppID() ?>',
              cookie: true,
              xfbml: true,
              oauth: true
            });
            FB.Event.subscribe('auth.login', function(response) {
              window.location.reload();
            });
            FB.Event.subscribe('auth.logout', function(response) {
              window.location.reload();
            });
          };
          (function() {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol +
              '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
          }());
        </script>
      </body>
    </html>
    

    Now depending on your application, you may want to use subscribe to the auth.authResponseChange event to always insure you “know” the latest state of the current user (still logged-in…etc):

    FB.Event.subscribe('auth.authResponseChange', function(response) {
        window.location.reload();
    });
    

    Or you may choose to check whenever you require an action from the user and in this case you would use the FB.getLoginStatus() method:

    function call_to_action() {
        FB.getLoginStatus(function(response) {
            if (response.authResponse) {
                // logged in and connected user, someone you know
    
                // proceed with your flow
            } else {
                // no user session available, someone you dont know
    
                // trigger FB.login() ...etc
            }
        });
    }
    

    Now you always place members related content within if($user) statement:

    <?php if($user) { ?>
        <p>s3cr3t data</p>
    <?php } else { ?>
        <p>Please login!</p>
    <?php } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There may be situations where I would need to find an object by parameters
I would need to create a temp table for paging purposes. I would be
I would need some basic vector mathematics constructs in an application. Dot product, cross
I would need to get a Regular Expression, which matches all Unicode control characters
I would need to build a html table that has a horizontally scrollable column.
What regex pattern would need I to pass to java.lang.String.split() to split a String
Does anyone know what would be the minimum rights I would need to grant
I'm working on a tool which would need to communitacte: send and recieve files
I have a project in which I would need to copy files found within
I've got an MS access database and I would need to create an SQL

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.