Roopa
Roopa

Reputation: 159

how to set different time out limit for different sessions in php

Can we set diff time out limit for diff session variables in php?

For eg: $var1 = $_SESSION['var1'];

$var2 = $_SESSION['var2'];

I want $_SESSION['var1'] to expire after 5 mins while $_SESSION['var2'] should expire after 30 mins..

Thanks

Upvotes: 0

Views: 359

Answers (1)

Pekka
Pekka

Reputation: 449515

Nope, this is not possible natively.

You will have to implement this on your own. You would have to store creation date, expiry time, and value for every variable, and then maybe create a class that handles the checking.

You could use the __get() and __set() magic methods to build a very convenient interface that handles like this:

$data = new SessionData();
echo $data->var1; // Using a __get() magic method, the class checks for 
                  // the expiry time and returns the value if it is still valid

Upvotes: 1

Related Questions