note 63837 added to ref.session

From: Date: Sat, 01 Apr 2006 12:47:22 +0000
Subject: note 63837 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-107126@lists.php.net to get a copy of this message
Fairly new to PHP, I've been looking to alter session timeouts on a shared host where I don't have direct access to configure php.ini. There doesn't appear to be any easy way to find out how to do this in this manual (nor from a quick web search). The code below seems to work OK to set session timeout. a timeout of 30 secs is used for convenient testing. gc settings must come before session_start(). The garbage collection is made 100% by setting probability and divisor to the same value - if I have correctly understood what these functions do. (on the first pass of the file, there is no session file - that's established only when the script ends for the first time. Keep reloading to test). Comments welcome. <?php ini_set('session.gc_maxlifetime',30); ini_set('session.gc_probability',1); ini_set('session.gc_divisor',1); session_start(); // check to see what's happening $filepath = ini_get('session.save_path').'/sess_'.session_id(); if(file_exists($filepath)) { $filetime = filemtime ($filepath); $timediff = mktime() - $filetime; echo 'session established '.$timediff.' seconds ago<br><br>'; } ?> ---- Server IP: 85.116.0.130 Probable Submitter: 81.151.14.223 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.session.php Edit -- http://master.php.net/note/edit/63837 Del: integrated -- http://master.php.net/note/delete/63837/integrated Del: useless -- http://master.php.net/note/delete/63837/useless Del: bad code -- http://master.php.net/note/delete/63837/bad+code Del: spam -- http://master.php.net/note/delete/63837/spam Del: non-english -- http://master.php.net/note/delete/63837/non-english Del: in docs -- http://master.php.net/note/delete/63837/in+docs Del: other reasons-- http://master.php.net/note/delete/63837 Reject -- http://master.php.net/note/reject/63837 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107126) next »