0

Possible Duplicate:
Extending Session Timeout in PHP

I have php sessions where the problem I could have is that if for a long time I do not use the application, if I refresh the web browser, I suddenly get Notices on all my $_SESSION's. I want to know if it is possible that if I have not used a web page for a long time, that if I refresh a page, the $_SESSIONs remain intact?

I know the @ symbol can be used but is that only to not show the error message? I just don't want it to ever stop the session.

Thanks

Community
  • 1
  • 1
user1394925
  • 754
  • 9
  • 28
  • 51

3 Answers3

2

The notices you are getting likely describe what is wrong with your code. Consider correcting your code so you don't get notices, instead of avoiding the case where your errors manifest.

lanzz
  • 42,060
  • 10
  • 89
  • 98
  • Well what is happening is lets say you log in to a page by typing in your username and password, the details of those details are stored in a session. But after a period of time, if you click on the refresh button lets say 5 hours later, then you could get notices on those sessions. What ways could I use to fix the code? Any examples – user1394925 Jun 04 '12 at 21:40
  • 1
    You could check if the session vars you're trying to access actually exist in the session. In cases where you simply check if a value is true (e.g. `if ($_SESSION['userId']) { // do something...`), it is safe to suppress the notice (`@$_SESSION['userId']`); in more complex cases you should make proper effort to validate the state of your `$_SESSION` container. – lanzz Jun 04 '12 at 21:43
  • 2
    @user1435599 In most cases isset is your friend. :-) http://php.net/manual/de/function.isset.php – Oliver Jun 04 '12 at 21:44
0

Your goal should not be to make the session longer but to remove the notices.

As @ceejayoz mentioned by repairing your code not by supressing errors.

Oliver
  • 2,864
  • 1
  • 16
  • 27
0

If you want to extend the length of the session, try ini_set('session.gc_maxlifetime', '3600');, where "3600" is the length of time in seconds you want the session to last. If you want the session to last permanently, I would suggest putting a very large number there.

demize
  • 364
  • 1
  • 15