Stut a écrit :
On 2 Mar 2008, at 14:49, Richard wrote:
I'm quite new to sessions, an am trying to program a script which
needs two sessions ...
I have a members area which uses 1 session, and when you click on
disconnect it closes the session and the user returns to the login page.
I also am programming a shopping cart so members can choose what they
would like to download that also uses a session.
All worked fine untill I realised that because they both use the same
session, when I disconnect from the members area it also obviously
deletes all elements from the download cart.
I would there for need to have two seperate sessions one for the
cart, and one for the members area. And sometimes I will need to have
them both open.
Is this possible ? I've searched google but not found anything
interesting, except session_name, but I still don't know how to open
two sessions or close one session but not the other, or open a
variable in a specific session ...
Just use one session. Put the data for each session into a separate
array...
$_SESSION['members'] = array('lots', 'of', 'data');
$_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap');
To "disconnect" the user from one or other simply unset that variable...
unset($_SESSION['members']);
unset($_SESSION['cart']);
KISS.
-Stut
Thankyou, instead of unsetting the whole session, I just unset de
password, so the user has to login again and now it does not reset the
cart anymore.
However, is there a way to limit the session stay alive time for just
one variable ?
If for example, if a user has not done anything in his members area for
more than 30 minutes I would like to be able to reset his password, but
I do not want to reset the cart. Do I have to program this seperatly in
PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on
each page loads :
if ( time() - $_SESSION[last_time] > 1800) {
$_SESSION['password'] = array();
else {
$_SESSION['last_time'] = time()
}
...
Or is there a better way to do this?
Thanks again :)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php