Search code examples
phpsessioncookiessession-cookies

would session or cookie timeout be different in Local Host vs Live


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.


Solution

  • 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.