note 16219 added to ref.session
| From: | shelby dot nospam at DownloadFAST dot nospam dot com | Date: | Sun, 21 Oct 2001 01:11:40 +0000 |
| Subject: | note 16219 added to ref.session | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-19216@lists.php.net to get a copy of this message | ||
Here is class for previous message:
<?
if( !isset( $_Session_class ) )
{
$_Session_class = 1;
// Client page (not browser) session
class Session
{
// Starts a new, or reloads current, session. Registers the
$HTTP_SESSION_VARS["SESSION"] array().
// The session_id() is retrieved from $HTTP_POST_VARS[session_name()] or
$HTTP_GET_VARS[session_name()]
// Note: this must be called before any output as this set some values the http headers
// IMPORTANT: define (include) any classes which are stored in the session before calling this!
Session()
{
global $HTTP_GET_VARS;
global $HTTP_POST_VARS;
global $HTTP_SESSION_VARS;
// Make sure sessions do not depend on HTTP_REFERER
assert( ini_get( "session.referer_check" ) == ""
|| (ini_set( "session.referer_check", "" ) && ini_get(
"session.referer_check" ) == "") );
// Let browser decide caching
// (PHP's default is no-cache which is unnecessary extreme given we block herein out of sync
POST or GET)
session_cache_limiter( "" );
// Get existing session?
$is_new = 0;
if( isset( $HTTP_POST_VARS ) && isset( $HTTP_POST_VARS[session_name()] ) )
{
session_id( $HTTP_POST_VARS[session_name()] );
}
else if( isset( $HTTP_GET_VARS ) && isset( $HTTP_GET_VARS[session_name()] ) )
{
session_id( $HTTP_GET_VARS[session_name()] );
}
else
{
$is_new = 1;
}
// Start the session
session_start();
// Unset and unregister all session variables in case a previous cookie session existed?
if( $is_new )
{
session_unset();
foreach( $HTTP_SESSION_VARS as $name => $value )
{
unset( $name );
}
}
// Destroy and restart the session so any cached (out of sync) pages lose their session if
resubmitted.
// Copy and restore any variables so they are not destroyed
$t = $HTTP_SESSION_VARS;
foreach( $t as $name => $value )
{
session_unregister( $name );
}
session_destroy();
session_start();
foreach( $t as $name => $value )
{
session_register( $name );
$HTTP_SESSION_VARS[$name] = $value;
}
unset( $t );
while( 1 )
{
// Initialize and register the global array?
if( !session_is_registered( "SESSION" ) )
{
session_register( "SESSION" );
if( !isset( $HTTP_SESSION_VARS["SESSION"] ) )
{
$HTTP_SESSION_VARS["SESSION"] = array();
}
}
// For enhanced security (and less chance for error if we change site code while a session is
active),
// insure that sessions only live for 15 minutes of no activity.
// This protects against someone leaving their workstation unattended after login
if( isset( $HTTP_SESSION_VARS["SESSION"]['session_timeout'] )
&& $HTTP_SESSION_VARS["SESSION"]['session_timeout'] < time() )
{
session_unset();
unset( $HTTP_SESSION_VARS["SESSION"] );
session_destroy();
session_start();
continue;
}
$HTTP_SESSION_VARS["SESSION"]['session_timeout'] = time() + 15 * 60;
break;
}
}
} // class Session
} // if( !isset( $_Session_class ) )
?>
--
http://www.php.net/manual/en/ref.session.php
http://master.php.net/manage/user-notes.php?action=edit+16219
http://master.php.net/manage/user-notes.php?action=delete+16219
http://master.php.net/manage/user-notes.php?action=reject+16219