jaymc Posted January 10, 2007 Share Posted January 10, 2007 For some reason sessions are 'dying' randomly for no reasonI do have a refresh on my site which calls the session then does some sql queries, im just wondering if it could be thatBut then again, ive had the site running for over an hour with no problemsGenerally, what causes sessions to dieWHen reading a session in a page do i need to dosession_start();$sessionvar = $_SESSION['name'];Or can i just do $sessionvar = $_SESSION['name']What can I look for in my code that my point to why the session is being destroyed.. Quote Link to comment Share on other sites More sharing options...
Asheeown Posted January 10, 2007 Share Posted January 10, 2007 [code]<?phpsession_start();header("Cache-control: private"); $sessionvar = $_SESSION['name'];?>[/code][quote]header("Cache-control: private");[/quote]Is a security fix that was added in.Sessions don't die unless you unset them or you exit your browser, check your php.ini file and see how long your sessions last Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 11, 2007 Author Share Posted January 11, 2007 What exactly is the purpose of [b]header("Cache-control: private");[/b]And should I be doing session_start(); in every single page in which I am reading the session fromBecause I can still read the session without session_start() Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 lol yes you need to use session_start() on every page. I would use a config file which is included on every page. Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 11, 2007 Author Share Posted January 11, 2007 How come its working without doing that then?Can it be set in the php.ini conf to start if not requested to start, I was in there before and seen something similarBut definetly Im not using session_start() apart from when logging in and its working ok? Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Yes, there is a session.auto_start directive in the php.ini. I would however ignore this and persist in using session_start() in all your scripts, your code will not be at all portable otherwise and its a bad habbit to get into. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 "But definetly Im not using session_start() apart from when logging in and its working ok?""For some reason sessions are 'dying' randomly for no reason"These statements cannot coexist. Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 11, 2007 Author Share Posted January 11, 2007 It does just appear to be happening in FirefoxIve added session start in all of the pages now... Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 11, 2007 Author Share Posted January 11, 2007 Yes, its just firefox in which its doing it in...However, I do have the site open in IE and Firefox at the same timeIs it a case of the session only being valid for one of the browser?In other words, is the session from IE killing the session file from firefox? Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 11, 2007 Author Share Posted January 11, 2007 Edit: Just to confirm, this is only happening in firefoxIn IE their is no problem at allAny ideas? Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 12, 2007 Author Share Posted January 12, 2007 More infoIt is happening in IE aswell, but its a lot more frequent in firefoxIn php.ini the session.cookie timeout is set to 86400 so something must be terminating the sesion right?But Ive been through all my scripts and the only thing they have regarding sessions is session_start();$User_Session = $_SESSION['username'];Thats all Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 I think this may be your end. Either your browsers are misconfigured...or you're imagining some stuff. Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 12, 2007 Author Share Posted January 12, 2007 It is happening to other people..Ive had like 50 people test this out and about 9 have came back and said yes its happening to me also..Its driving me mad I simply cant find a bad piece of code or server configuration to write this off asWhat could cause the termination of a session cookie that has been set for 86400 seconds Quote Link to comment Share on other sites More sharing options...
trq Posted January 12, 2007 Share Posted January 12, 2007 [quote]What could cause the termination of a session cookie that has been set for 86400 seconds[/quote]The closing of the browser. Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 13, 2007 Author Share Posted January 13, 2007 [quote author=thorpe link=topic=121834.msg503596#msg503596 date=1168642586][quote]What could cause the termination of a session cookie that has been set for 86400 seconds[/quote]The closing of the browser.[/quote]The browser is not being closedSeriously, it just appears to be killing its self when it pleases... Quote Link to comment Share on other sites More sharing options...
trq Posted January 13, 2007 Share Posted January 13, 2007 Well, Im sorry but I can't really offer any solution. What you should do though is turn on error logging in your php.ini. Then view those logs. You might be having some sort of permissions issue on the server side that is stopping the local sessions from being saved. Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 13, 2007 Author Share Posted January 13, 2007 Any ideas? Please Quote Link to comment Share on other sites More sharing options...
Asheeown Posted January 13, 2007 Share Posted January 13, 2007 I believe thorpe just gave a very reliable solution while it does require a certain amount of work it is almost guaranteed to work Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 What is a session cookie? A Cookie is different than a Session Quote Link to comment Share on other sites More sharing options...
trq Posted January 13, 2007 Share Posted January 13, 2007 [quote]What is a session cookie?[/quote]Sessions use cookies. Well, they do by default anyway, otherwsie you need to pass the session id around in the url. Session cookies store the session id on the client, then, there is also a session file (cookie) stored on the server. This is how php is able to recognise one session from another. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 Ah I getcha :) I got confused for a second. Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 13, 2007 Author Share Posted January 13, 2007 [quote author=thorpe link=topic=121834.msg503647#msg503647 date=1168647656]Well, Im sorry but I can't really offer any solution. What you should do though is turn on error logging in your php.ini. Then view those logs. You might be having some sort of permissions issue on the server side that is stopping the local sessions from being saved.[/quote]That could be feasable, but, how would the sessions be created in the first place and work fine anywhere from 1 minute to 3 hours...I have an invision forum on the site and that is running fine, not sure if it uses session cookies etc...But yeh, what your saying my site would either WORK or NOT WORK, I cant see any room for it working ok for a minute or 3 hours then screwing up...Hmmm? Quote Link to comment Share on other sites More sharing options...
trq Posted January 13, 2007 Share Posted January 13, 2007 sessions shouldn't be lasting 3 hours anyway, by default its something like 20 minutes. Invision more than likely uses a custom session handler which would store the sessions in the database. Mosdt forums do, its easier to create 'who's online' type scripts.Im sorry, but I have no other ideas. Quote Link to comment Share on other sites More sharing options...
jaymc Posted January 13, 2007 Author Share Posted January 13, 2007 I've enabled php error logging in php.iniWhere is the error log file ? Quote Link to comment Share on other sites More sharing options...
trq Posted January 13, 2007 Share Posted January 13, 2007 By default it should go to the system logger. Hope youve got shell access, try...[code]/var/log/php[/code]If its a shared host, Im not sure, you'd need to contact your host. 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.