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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:51:35+00:00 2026-05-26T15:51:35+00:00

For background, here’s my scenario: I’m building a self-hosted platform for a particular niche,

  • 0

For background, here’s my scenario:

I’m building a self-hosted platform for a particular niche, and part of that platform is the login process, which if validated sets a session for the user. On every administration page load, the session is started and the variable $_SESSION['key'] checked to see if it’s true.

If it’s false, the user is re-directed to the login page with an error telling them to login again.

The problem is this is dependant on a session cookie being set or not set, in the sense that when the session cookie expires and the session is started with session_start() to check $_SESSION['key'], therefore creating a new session cookie with default values (I use session_set_cookie_params() to alter the path, timeout etc) making it impossible to re-login as session cookies do not overwrite from what I can see.

In order to fix this I’ve thought about using something like session_set_cookie_params(5, ..) before session_start() when checking $_SESSION['key'], which will create a 5 second session cookie, therefore allowing a new one to be created when re-logging in, but I’m not sure whether this would work – and I’m also sure there must be a more efficient way to set/unset a session variable?

Here’s my code:

Start session if validated login

if($validated){
    session_set_cookie_params(1800, "/inst", $server_name['home']); 
    session_name("_inst");
    session_start();
    $_SESSION['key'] = true;
}

Check if $_SESSION[‘key’] is still true

session_name("_inst");
session_start();

if(!$_SESSION['key']) {
    header('Location: ' . $server['home'] . '/login/?error=1');
}

Any answers or advice would be great, and please do ask if you need clarification on anything!

  • 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-26T15:51:35+00:00Added an answer on May 26, 2026 at 3:51 pm

    Just issue a session_start() on all pages. This’ll unconditionally create a session for you, then you can check for the presence/abscence of the key:

    <?php
    
    session_start();
    
    if (!isset($_SESSSION['key'])) { // never logged in, or were logged in and got logged out
       ... redirect to login ...
       exit();
    }
    
    if ($_SESSION['key'] != 'expected value') { // logged in, but no longer a valid login.
       ... redirect to login ...
       exit();
    }
    

    You shouldn’t have to mess with the session cookie settings at all. Leave them at default and simply check for the relevant key(s). if they’re not there, then the user is not logged in and should be redirected.

    If their session had expired and PHP cleaned up the session file, then they’ve been effectively logged out, even though they have a it-was-valid-at-one-point-in-time session key, and should get redirected to login again.

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

Sidebar

Related Questions

I have this query which works correctly in MySQL. More background on it here
Here's my regex code: preg_match_all('/background[-image]*:[\s]*url\([|\']+(.*)[|\']+\)/', $css, $matches, PREG_SET_ORDER); It looks for CSS that looks
I have an Ul of item. I want to alternate there background color here
I have googled an serached a lot here about background runnin aps but have
Here is the background, I am trying to create a DSL to allow customer
Here's my CSS: #social #twitter { background-image: url(../img/twitter.svg); max-height: 32px; max-width: 32px; } And
Here is an example of what I'd expect: Input: a { background: red; }
Here are my jquery mobile checkboxes i want to change its background color. i
Here's a screenshot of my AlertDialog's unresponsive state: In the background, the green tile,
In the status notification doc here i read : A background service should never

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.