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

  • Home
  • SEARCH
  • 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 7840273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:43:32+00:00 2026-06-02T15:43:32+00:00

we have set session_gcmaxlife=5 in php.ini but session variable on server are not destroyed

  • 0

we have set
session_gcmaxlife=5
in php.ini but session variable on server are not destroyed after 5 seconds

We want to set the maximum life of the session in PHP to be 5 seconds.

  • 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-06-02T15:43:34+00:00Added an answer on June 2, 2026 at 3:43 pm

    OK – to me a 5 second session sounds rather pointless (as a session is supposed to maintain the application state in a stateless application… yeah).

    Your best bet is to probably save an expiry timestamp (time() + 5 seconds) in the session, something like $_SESSION['expires'] – then whenever you start a session, check to see if that variable exists and, if so (and is in the past), kill the session off and start again.


    [EDIT]

    This is one other possibility that might work, but you’d need to create an object to manage your session – then you could have a kill() method that could be invoked if the session has expired and in the __destruct() method – it’s not fullproof as the destructor will only be invoked when the object is destroyed – but it should work.

    class Session {
    
      private static $_instance;
    
      //private constructor to prevent external instantiation
      private function __construct($sSessName, $sSavePath, $iGCLifetime, $sCookieDomain, $sCookiePath) {
    
        //session parameters
        ini_set("session.save_path", $sSavePath);
        ini_set("session.gc_maxlifetime", $iGCLifetime);
        ini_set("session.use_trans_sid", false);
    
        //session cookie parameters
        ini_set("session.use_cookies", true);
        ini_set("session.use_only_cookies", true);
        ini_set("session.cookie_domain", $sCookieDomain);
        ini_set("session.cookie_path", $sCookiePath);
        ini_set("session.cookie_lifetime", 0);
    
        //set the session name
        session_name($sSessName);
    
        //set the session cookie paramaters
        session_set_cookie_params(0, $sCookiePath, $sCookieDomain);
    
        //start the session
        session_start();
    
        //check to see if the session has expired - and if so kill it
        if(isset($_SESSION['expires']) && time() > $_SESSION['expires']) {
          $this->kill();
        }
    
        //if not - set the expiry time in the session
        else {
          $_SESSION['expires'] = time() + 5;
        }
      }
    
      //destructor function _should_ kill the $_SESSION when the object is destroyed
      public function __destruct() {
        $this->kill();
      }
    
      //session killer
      public function kill() {
        //kill the session cookie
        setcookie(session_name(), null, time()-3600);
    
        //kill the session
        session_unset();
        session_destroy();
      }
    
      //Singleton instance getter
      public function getInstance() {
        if(!self::$_instance) self::$_instance = new self();
        return self::$_instance;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried the obvious SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED, but my
In my web application I have set the session timeout for 30 minutes. But
I have an aspx page (page1.aspx) where I set a Session variable and then
I have set cookie and set it to expire after sufficient seconds. Still as
I have set the FlushMode property on an NHibernate session to FlushMode.Never, but when
i want to set session time out limit by 3 min , i have
In the configuration properties of my javax.mail.Session I have set mail.debug=true , but for
I have set up a login area on my PHP server. The members.php file
I have set a session scope object in my session and I want to
I am currently in C# and I have set Session variables on each page.

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.