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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:15:57+00:00 2026-05-24T12:15:57+00:00

Currently I have been testing variables on $_SESSION, and if isset() returns false then

  • 0

Currently I have been testing variables on $_SESSION, and if isset() returns false then assume the session has timed out to show a login page.

session_start();

if (isset($_POST['login'])):
  // Process login credentials
  $_SESSION['account'] = Array('user'=>'username');
endif;

if (! isset($_SESSION['account'])):
  // User not logged in, show login page
else:
  // User is logged in, show account page
endif;

However a user has recently reported that the account page was blank. I assume no session data was available because my code above is flawed somehow. Could someone point me in the right direction to correctly test if a session has timed out in PHP?

  • 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-24T12:15:58+00:00Added an answer on May 24, 2026 at 12:15 pm

    if you could use:

    if (! isset($_SESSION['account']) && !empty($_SESSION['account'])):
      // User not logged in, show login page
    else:
      // User is logged in, show account page
    endif;
    

    so this wont pass for 2 conditions,

    1. if session isn’t set

    2. if session is set, but is blank!

    still a case exist of invalid values, for eg, username comes to xyz and you dont have any record matching xyz, then it could be a case of fetched no records and therefore it could be blank too!

    so more than just these statements, you should have a further check that if the data in $_POST matched to any of your records in the systems, and only after the match is confirmed, you should set this in to $_SESSION.

    And these should cover most of your cases, making escapes lesser!

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

Sidebar

Related Questions

I've been trying to implement unit testing and currently have some code that does
I currently use Notepad++ for most of my development. I have been checking out
I've been doing some work testing web applications with Cucumber and I currently have
I have been involved in doing web automation and Android automation testing. Currently we
I am currently testing a small application I have written. I have not been
I have been investigating building web parts for sharepoint 2010 and currently have a
I have been trying to get more in to TDD. Currently keeping it simple
I have been working on keeping things object oriented for my project. Currently, I'm
Currently, I have been reading lists of data from a binary data file programmatically
I'm currently monitoring a large network with Hobbit and have been tasked with lowering

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.