top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Making a Timeout Expiration Length to Session Variables using PHP

0 votes
378 views

I would like to make a timeout length to session variables, so that if a user didn't use the browser page for let's say 5 minutes - the session variables would expire and the user would need to login again.

Q: What's the best way to implement this functionality?

posted Jul 8, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

You can either use cookies or do something like that:
http://stackoverflow.com/questions/3068744/php-session-timeout

In your case is would be
if ($_SESSION['timeout'] + 5 * 60 < time()) {
// session timed out
} else {
// session ok
}

answer Jul 8, 2013 by anonymous
Similar Questions
0 votes

I want to use session to pass variables through pages using php.
Site structure is:
1. header.php
2. column.php
3. footer.php
4. index.php
Pages 1, 2 & 3 are included into the index.php.

In header.php page, there is a drop down, in which links(cities) are placed where users will select city.
Now, I want to do code to store selected values into a variable and pass to multiple pages.

Please help on this..

0 votes

I have a question about using a php user class and session variables. Let's say that I have managed to create a user class that finds a particular person from the database query.

As I move about the site from page to page it would be nice to be able to use the current user inside the user class without needing to re – look them up in the database multiple times

Q: so is there a way to combine the current active user in the class with session variables so that they can be used multiple times? If so, how would this work?

+1 vote

Why I can't read static variables of a child class, even so the variable is protected or public?

Here's what I tried:

class A {
 protected static $foo = "bar";
}

class B {
 public function readFoo() {
 return self::$foo;
 }
}

When now calling B::readFoo, I get the following error:

var_dump((new B())->readFoo());

PHP Fatal error: Access to undeclared static property: B::$foo in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. B->readFoo() php shell code:1

Fatal error: Access to undeclared static property: B::$foo in php shell
code on line 1

Call Stack:
 86.2643 231224 1. {main}() php shell code:0
 86.2666 231352 2. B->readFoo() php shell code:1
...