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 5961265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:56:26+00:00 2026-05-22T18:56:26+00:00

My website uses Facebook connect for login and the session lifetime on my server

  • 0

My website uses Facebook connect for login and the session lifetime on my server is 3600.

I’m using Client-Side Flow (javascript) redirect to login.php, and login.php retrieve cookies (set by javascript) to get access token.

However, if a user is idled over 3600 seconds, the session on my server expires. ($_SESSION[‘uid’] does not exists.)
How can my login.php check the user has already logged in Facebook(not my app) or not?

The solution I’m using is to redirect the user to my javascript page, and “onStatus function” would be automatically trigged by facebook.

I’m searching for a solution which can all be done with login.php to automatically relogin my website if he or she has logged in Facebook (without redirecting to javascript page). Is is possible?

javascript:

FB.init({appId: 'MY_APP_ID', status: true, cookie: true, xfbml: true});

FB.getLoginStatus(function(response) {
    onStatus(response);
    FB.Event.subscribe('auth.statusChange', onStatus);
    FB.Event.subscribe('auth.login', reloadPage);
});

function onStatus(response) {
    if (response.session) {
        window.location.href = '/login?fb';
    }
}

function reloadPage(response) {
    if (response.session) {
        window.location.href = '/login?fb';
    }
}

PHP (for login):

function get_facebook_cookie($app_id, $app_secret) {
  $args = array();
  if(!isset($_COOKIE['fbs_' . $app_id]))
      return false;
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $app_secret) != $args['sig']) {
      return false;
  }
  return $args;
}

$cookie = get_facebook_cookie(MY_APP_ID, MY_APP_SECRET);

if($cookie){
    if($result = @file_get_contents("https://graph.facebook.com/me/?access_token=".$cookie['access_token'])){
        $result = json_decode($result, true);
        $_SESSION['uid'] = $result['id'];
    }
  • 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-22T18:56:27+00:00Added an answer on May 22, 2026 at 6:56 pm

    I’ve figured out a way to do so. To iframe the following page in all pages.

    When the access token gave by facebook through cookie expires, page in iframe auto refresh.
    And FB.init() would set up a new access token(cookie) for my app.

    In my php files, just check the cookies as first connected.

    fb_keepalive.html:

    <div id="fb-root"></div>
    <script type="text/javascript" src="https://connect.facebook.net/zh_TW/all.js"></script>
    <script type="text/javascript">
    FB.init({appId: 'APP_ID', status: true, cookie: true, xfbml: true});
    FB.getLoginStatus(function(response) {
        onStatus(response);
    });
    
    function onStatus(response) {
        if (response.session) {
            var timestamp = new Date().getTime();
            var expires = response['session']['expires'] * 1000;
            if(expires - timestamp >= 0){
                setTimeout(function(){window.location.reload();}, expires - timestamp);
            }
        }
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop a website which uses Facebook Connect for authentication and other
We have a website that uses Facebook for login. We have an invite page
Im working for a company who's website uses javascript to get facebook and twitter
I follow this tutorial to integrated facebook : http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/ The problem is that when
I am building a website that uses facebook connect for users to log in,
I have a website that uses the facebook, twitter, delicious share links. They contain
My website uses Response.Redirect(~/Main/Main.aspx) type redirects all over the place. Worked flawlessly until the
I've got a new website moved to my server. This website uses PHP and
I am building a website for a comedy group which uses Facebook as one
I am trying to implement Facebook Connect functionality into a website that I am

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.