aniesh82 Posted June 20, 2007 Share Posted June 20, 2007 Hello Friends, I need to register a session as infinity. How can I do this? Could someone help me ? I also tried with the following code, but did not work. ini_set("session.gc_maxlifetime","864000"); Quote Link to comment Share on other sites More sharing options...
aniesh82 Posted June 21, 2007 Author Share Posted June 21, 2007 I tried by editing the php.ini I have set ini_set("session.gc_maxlifetime","864000"); ini_set('session.cookie_lifetime',"864000"); in the php script and added one php.ini file in the directory which it executes. But session get expired after some hours. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
trq Posted June 21, 2007 Share Posted June 21, 2007 Use cookies. Sessions are not made for this. Quote Link to comment Share on other sites More sharing options...
aniesh82 Posted June 21, 2007 Author Share Posted June 21, 2007 I do not get how to use cookies to solve this problem. Could you please explain a bit more? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 21, 2007 Share Posted June 21, 2007 You cannot have an indefinite session or cookie - you can set the expiry time to a long way into the future but you should NOT use sessions for that - I believe they should be left to expir when the browser closes... Quote Link to comment Share on other sites More sharing options...
aniesh82 Posted June 21, 2007 Author Share Posted June 21, 2007 hello ToonMariner, When we login in PHPFREAKS can select any the option from select box like one hour, 2 hour, one day etc. Did you note that ? I closed my browser and I returned on the next I saw that login exists. How it happened? Quote Link to comment Share on other sites More sharing options...
trq Posted June 21, 2007 Share Posted June 21, 2007 How it happened? Cookies. if the user selects to be logged in forever, create a cookie that says so. Then, next visit, check for the existence of this cookie, if it exists, log the user in using sessions. Quote Link to comment Share on other sites More sharing options...
aniesh82 Posted June 21, 2007 Author Share Posted June 21, 2007 Thorpe, Thanks for your reply. So it is not possible to do this using sessions? I am not sure but I think that, session id is stored in browser as a cookie, when we register a new session by server to identify the browser. If this happen, how is not possible to store the session id as a cookie exists forever like you says ? Quote Link to comment Share on other sites More sharing options...
trq Posted June 21, 2007 Share Posted June 21, 2007 If this happen, how is not possible to store the session id as a cookie exists forever like you says ? It may be, but its not practical. That is not the intended pupose of sessions. What is wrong with cookies? That is there intended purpose. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 21, 2007 Share Posted June 21, 2007 the sessions data would then have to be stored indefinitley on the server - and imagine storing 2000000 cookies that no one is using!!!!! Quote Link to comment Share on other sites More sharing options...
aniesh82 Posted June 21, 2007 Author Share Posted June 21, 2007 Thanks for your Quick Response. Quote Link to comment Share on other sites More sharing options...
suma237 Posted June 22, 2007 Share Posted June 22, 2007 hi, In which application you will be using infinite session.? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 its a poor programing idea because your server would become overwhelemed with stored session IDs because you said to not delete them forever Quote Link to comment Share on other sites More sharing options...
corbin Posted June 22, 2007 Share Posted June 22, 2007 Let's pretend that you're coding some form of login script.... The suedo-php for this could be as follows: if(session is set) { show page } else { if(cookie containing username and password is set) { if(username and pass are correct) { set session set cookie (if you want to...) exit script } else { unset cookie echo wrong pass } } elseif(POST data containing username and password is set) { if(username and pass are correct) { set session and cookie refresh page exit script } else { echo wrong pass } } } html form for logging in goes here It could actually be done a little shorter/more efficiently, but in suedo-code, that seemed like the best way. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.