Jump to content

Sessions dying


jaymc

Recommended Posts

For some reason sessions are 'dying' randomly for no reason

I do have a refresh on my site which calls the session then does some sql queries, im just wondering if it could be that

But then again, ive had the site running for over an hour with no problems

Generally, what causes sessions to die

WHen reading a session in a page do i need to do

session_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..
Link to comment
Share on other sites

[code]<?php
session_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
Link to comment
Share on other sites

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 from

Because I can still read the session without session_start()
Link to comment
Share on other sites

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 similar

But definetly Im not using session_start() apart from when logging in and its working ok?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Yes, its just firefox in which its doing it in...

However, I do have the site open in IE and Firefox at the same time

Is 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?
Link to comment
Share on other sites

More info

It is happening in IE aswell, but its a lot more frequent in firefox

In 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
Link to comment
Share on other sites

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 as

What could cause the termination of a session cookie that has been set for 86400 seconds
Link to comment
Share on other sites

[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 closed

Seriously, it just appears to be killing its self when it pleases...
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.