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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:48:46+00:00 2026-05-25T13:48:46+00:00

In my PHP app, I’m trying to differentiate between cases where an unset session

  • 0

In my PHP app, I’m trying to differentiate between cases where an unset session variable is due to an actual bug or due to something that’s not my fault (ie. the user logged out or manually typed a URL). Obviously, I want to record bugs only. Right now I’m recording errors for both and I can’t tell which is which.

Are there some generally accepted ways of dealing with this sort of thing? I am curious to hear how others out there have approached this situation.

Thanks, Brian

  • 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-25T13:48:46+00:00Added an answer on May 25, 2026 at 1:48 pm

    Set all session variables to a sane default when the session is created. If at any later point you find an unset session variable, it’s a bug.

    If the user logs out, that does not mean they don’t have a session (or it should not mean that, if your session handling is anything like most implementations). The same goes for manually typing a URL. At some point, your app’s internal framework is necessarily doing session_start() for all page views. That’s a good place to inject defaults.

    Injecting defaults is dead easy with the array union operator:

    $defaults = array(
        'userid' => null,
        'lang'   => 'en',
    );
    
    session_start();
    $_SESSION['userid'] = 42;
    $_SESSION += $defaults; // will not overwrite existing values
    
    print_r($_SESSION);
    

    See it in action (and please ignore the warnings related to not being able to set the session cookie etc).

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

Sidebar

Related Questions

I'm a liferay newbie. I'm trying to write a simple php app that echos
I'm writing my first PHP app that has to directly deal with dates, and
In my (PHP) web app, I have a part of my site that keeps
My PHP app has an import script that can import records. At the moment,
My PHP app has a number-crunching part that is just to slow for PHP,
I'm writing a PHP app that has a 'control panel' that writes a prefs
I have a PHP app that creates a CSV file which is forced to
I have a PHP app index.php that, for various reasons, needs to run other
I have a PHP app that uses a $_GET parameter to select JS/CSS files
I have a php app that calls a class called Client. Every so often

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.