PHP Session expire-minutes inactivity

PHP Session expire-minutes inactivity

session_cache_limiter('public');
session_cache_expire(15);
//should expire after 15  minutes inactivity

asy way to handle this, is to set a variable to $_SESSION
 every time the user visits the page after a successful login.
You can check that variable every time the page loads, and then
 you will know the last time they requested a page from the site,
 and can compare it to the current time to determine what to do from there.

session.gc_maxlifetime
session.gc_maxlifetime specifies the number of seconds after which data
 will be seen as 'garbage' and cleaned up. Garbage collection occurs
 during session start.

Furthermore, when using PHP's default session.save_handler files,
 the session data is stored in files in a path specified in session.save_path.
 With that session handler, the age of the session data is calculated on the
 file's last modification date and not the last access date.

if (isset($_SESSION['LAST_ACTIVITY']) &&
 (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
    // last request was more than 30 minutes ago
    session_unset();     // unset $_SESSION variable for the run-time
    session_destroy();   // destroy session data in storage
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp

          OR

if (!isset($_SESSION['CREATED'])) {
    $_SESSION['CREATED'] = time();
} else if (time() - $_SESSION['CREATED'] > 1800) {
    // session started more than 30 minutes ago
    session_regenerate_id(true);  
// change session ID for the current session and invalidate old session ID
    $_SESSION['CREATED'] = time();  // update creation time
}

Note that session.gc_maxlifetime should be at least equal to the
 lifetime of this custom expiration handler 1800 in this example.
Related Posts:
  • difference between print and echo - php print( ) is a function, echo is a language construct.  This means that print( ) returns a value, while echo doesn't. You can include print( ) but not echo in larger expressions. echo is  run very fast than  … Read More
  • Send Email from a PHP Script you use the mail() function (in combination with a web form in particular), make sure you check it is called from the desired page and protect the form with a CAPTCHA mail(to,subject,message,headers,parameters); <?php… Read More
  • Web-Based MySQL Administration Web-Based MySQL Administration At http://phpwizard.net/phpMyAdmin you will find a PHP Web application that can help you manage MySQL. It enables you to manage a MySQL database using a browser and makes administrative work… Read More
  • Third-party Cookies Third-party Cookies Third-party cookies come from other domain sources that have items, such as ads or images,  embedded on the page adjust cookie and site data permissions. Manage your cookies and site data - chrome … Read More
  • php -Mail Functions The mail() function requires an installed and working email subsystem for sending mail. The program to be used is defined by configuration directives in the php.ini file. A common pitfall is that these are not set up cor… Read More
  • PHP-Renaming Files and Directories Renaming  Files and Directories There are a few useful file and directory functions built-in to PHP which I'll cover in brief here. They include renaming and deleting files as well as listing files located in a… Read More
  • php implode array elements php implode array elements Join array elements with a string string. implode(string, arraypieces) Returns a string containing a string representation of all the array elements in the same order,  string between each e… Read More
  • php urlencode - Make a strong GET Query String  php urlencode URL-encodes a string, converting spaces into plus (+ ) signs. urlencode() makes a string safe to use as part of a URL. It does this by encoding every character within the string that may be misi… Read More
  • Get mail info with IMAP or POP3 To read mail using IMAP or POP3, which allows you to create a web-based email client. Use PHP's IMAP extension, which speaks both IMAP and POP3: // open IMAP connection $mail = imap_open('{mail.server.com:143}', &nb… Read More
  • Php tutorial - imagemagick Php tutorial - imagemagick Php tutorial - imagemagick - create, edit and compose bitmap  imagemagick is free software  to create, edit, and compose bitmap images in many formats from the commandline or via progra… Read More
  • php best tutorial-php variables PHP automatically creates variables for all the data it receives in an HTTP request. This can include GET data, POST data, cookie data, and environment variables. The variables are either in PHP's global symbol table or … Read More
  • PHP variable-related functions Cast a value from one type to other type:- doubleval(), intval(), strval() Set  type of a variable:- settype() Verify  the type of a variable:- is_array(), is_bool(), is_double(), is_float(), is_int(), … Read More
  • Displaying Browser Specific-php However, having seen some of the possible values of HTTP_USER_AGENT in the last chapter, you can imagine that there are hundreds of slightly different values. So it's time to learn some basic pattern matching.You'l… Read More
  • php Sessions page Php Sessions are used to help maintain the values of variables across multiple web pages. This is done by creating a unique session ID that is sent to the client browser. The browser then sends the unique ID back on eac… Read More
  • php-use the header() function-php An HTTP (HyperText Transfer Protocol) header is used to send information back and forth between the server and the client (the Web browser). Normally this information is in the form of HTML, which is why the address for Web … Read More