note 18296 deleted from ref.session by sniper
| From: | sniper@php.net | Date: | Tue, 21 Jan 2003 03:23:22 +0000 |
| Subject: | note 18296 deleted from ref.session by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-42490@lists.php.net to get a copy of this message | ||
Here's a simple way to have Embperl like sessions. This consist in a "special"
variable (a hash) wich is persistent and holds all the persistent data. In this case the easyest way
is to take directly the $HTTP_SESSION_VARS variable, and add a prepend.inc and append.inc files to
automaticly register and unregister variables like this:
---- prepend.inc ----
<?php
# In case you don't use sessions auto start
session_start();
foreach ( $HTTP_SESSION_VARS as $var => $val )
$OLD_SESSION_VARS[] = $var;
?>
---- append.inc ----
<?php
foreach ( $OLD_SESSION_VARS as $var )
if ( !isset( $HTTP_SESSION_VARS[$var] ) )
session_unregister( $var );
foreach ( $HTTP_SESSION_VARS as $var => $val )
session_register( $var );
----------
The add this files to your php.ini as auto_prepend and auto_append, and that's it...
All you have to do to use a persistent variable is to use it in the $HTTP_SESSION_VARS hash. Try
this script out with your new prepend and append files:
---- test.php ----
<?= $HTTP_SESSION_VARS["counter"]++ ?>
------------------
and refresh it several times.
To unregister a variable, just unset() it, like <? unset( $HTTP_SESSION_VARS["counter"]
); ?>
Hope it helps! :)