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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:23:11+00:00 2026-05-28T08:23:11+00:00

I am struggling to keep the Facebook session alive using PHP on my website.

  • 0

I am struggling to keep the Facebook session alive using PHP on my website.

I use both the JavaScript SDK and the PHP SDK to form the basis of my app.

The problem I am having is that when the “Facebook session” ends, my PHP script believes that you are logged out of Facebook. But, as soon as I call the FB.init() using the JavaScript SDK, the session comes back to life.

Is there anyway to achieve the same using the PHP SDK? Or can I set a custom expiry time on the Facebook session?

Extracted from comments

It seems that the session expire time is set to 2 hours but I am not certain about this. I don’t think calling the PHP api will make a difference. I need to explain a little clearer what is happening. Basically, if you arrive at my home page, you get the option to login via Facebook. If you do, this all works fine! Once you are logged in and you have authorized the app, this is okay until the session expires. When the session expires, it seems that the PHP SDK is unable to determine whether or not you are logged in via Facebook, however, the Javascript SDK is. I use getUser() for the PHP SDK.

In other words, because the session has expired, PHP thinks that you are no longer logged in via Facebook. The Javascript SDK is able to detect whether or not you are logged in, regardless of whether the session is there. When it realises you are, it recreates the session any way. But in order for the session to be picked up by PHP, the page obviously needs to be refreshed. This is the problem I have, because the page displays content based on your Facebook login, I need the PHP SDK to be able to recreate the session as well, so that it is not necessary to refresh the page.

  • 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-28T08:23:12+00:00Added an answer on May 28, 2026 at 8:23 am

    Ok… Not to sure what the exact details of why your session are acting like this – I must state too that I am not very well versed in PHP sessions and have not has extensive experience with them.

    My suggestion would be to let the JavaScript SDK do its work… let it “re-detect” your session successfully and after it has done so, make an AJAX call to your server. In the processing of that call you can create and re-initiate the PHP SDK hence reviving your session.

    Additionally you could call the FB.getAuthResponse periodically to ensure that the users session is still valid ( at least in the JavaScript SDK ).

    From the Fb.getLoginStatus() documentation :

    {
        status: 'connected',
        authResponse: {
            accessToken: '...',
            expiresIn:'...',
            signedRequest:'...',
            userID:'...'
    } }
    

    By testing for the presence of the authResponse object within the
    response object, you can be sure the user is known to your app and you
    can begin to make further calls to the Facebook APIs. If the
    authResponse object is not present, the user is either not logged into
    Facebook, or has not authorized your app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently struggling to use UI elements in Interface Builder. I keep trying to
Design wise, I am struggling with where to keep items I use on the
I'm struggling to find a solution to keep using the Suhosin patch and make
i'm struggling with display/hide text using javascript here. Here is what i wanted to
So recently on a project I'm working on, we've been struggling to keep a
I'm struggling with this one. I need to randomly keep X percent of a
I'm struggling to use Twitter's Finagle library to implement an HTTP request to a
I am struggling to decide if I should be using the MySQL blob field
I keep hearing about the Entity Framework fluent-api but I am struggling to find
I'm struggling with Visual Studio 2008. I've used some form of Zen colors for

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.