You are here: Re: Sessions which do not expire... « All PHP « IT news, forums, messages
Re: Sessions which do not expire...

Posted by Fabian Hore on 02/23/06 19:09

I use a custom wakeup routine as a standard part of my PHP framework.
The following is taking from a class and has references to constants that
you won't have set,
but the principle should remain intact.
I hope it's of interest....


<?php
function start_session(){

if( session_id() ){
trigger_error("Session already started", E_USER_NOTICE);
return false;
}

defined('PLUG_SESSION_TIMEOUT') or define('PLUG_SESSION_TIMEOUT', 10);
defined('PLUG_SESSION_NAME') or define('PLUG_SESSION_NAME', 'PLUGSession');
session_name(PLUG_SESSION_NAME);

// Standard session cookie setup
ini_set('session.use_cookies', true);
ini_set('session.use_only_cookies', true);
ini_set('session.cache_limiter', 'nocache');
ini_set('session.cookie_lifetime', 0);

// garbage collection should be in sync with timeout value
if( PLUG_SESSION_TIMEOUT !== 0 ){
ini_set('session.gc_maxlifetime', PLUG_SESSION_TIMEOUT * 60);
// session.gc_probability can be set in general server config
}

session_start();
$tnow = time();

if(@$_SESSION['_plug_last_resume'] !== NULL && PLUG_SESSION_TIMEOUT !== 0){
// manually check session timeout
$tidle = $tnow - $_SESSION['_plug_last_resume'];
$tmax = PLUG_SESSION_TIMEOUT * 60;
if( $tidle > $tmax ){
// kill off SESSION vars - no need to destroy session
session_unset();
// tell core systems that session has timed out
if( class_exists('Auth') ){
Auth::on_session_timeout( $tidle );
}
header("X-PLUG-Session: expired-after-{$tidle}-seconds");
}else{
header("X-PLUG-Session: resume-after-{$tidle}-seconds");
}
}else{
header("X-PLUG-Session: new");
}

// record this session refreshment, whether new or not.
$_SESSION['_plug_last_resume'] = $tnow;
return true;
}
?>


you can read more about the framework if you're interested, here:
http://plug.whiteinteractive.com/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация