0

I am working on a simple web app which is PHP based both cookie and sessions are implemented. PHP.ini is customized as per the user requirement. My doubt is I don't want the session or cookie to be expired because if its expired so, the data array becomes empty which also throws an error. This case isn't happening in Local. I contacted my hosting provided regards, and what I was told is increasing max_exectution time. I did that as well but no luck.

I tested with the below piece of code to test on Live.

if((time()-$_SESSION['expire']) > 2){
   //code goes on to destroy session
}

this works fine. Instead If I try if((time()-$_SESSION['expire']) > 365*24*60*60) it expires in maybe 24 - 30 mins of inactivity. May I know why this happens? If I can make a session expire with above piece of code, why I am unable to keep it alive with the same time I setup up there. Please advice.

Roshan Zaid
  • 336
  • 1
  • 4
  • 21
  • You might want to have a look at these threads: [PHP sessions timing out too quickly](https://stackoverflow.com/questions/3476538/php-sessions-timing-out-too-quickly), [Why is my PHP session expiring prematurely](https://stackoverflow.com/questions/12021900/why-is-my-php-session-expiring-prematurely), and [How do I expire a PHP session after 30 minutes](https://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes) – nosurs Apr 04 '21 at 11:31
  • yea I read it. I don't get the point that why local hosting is fine and live server is where the issue is. – Roshan Zaid Apr 04 '21 at 14:19
  • Have you read the part about how session data & garbage collection is likely to be handled in a shared hosting environment, too? Besides, it's highly likely your php.ini settings are vastly different from those of your hoster. Anyway, you probably should implement your own session expiration handling as statet in [this answer](https://stackoverflow.com/a/1516338/3323348). – nosurs Apr 04 '21 at 15:47

1 Answers1

0

of course it is different from local hosting vs Live. as per the PHP code block I mentioned above, The session was timed out soon. If I increase the session save path as "/tmp" on htaccess and increase as the way I wanted, it helps.

Roshan Zaid
  • 336
  • 1
  • 4
  • 21