Sessions/Caching problem with Firefox 2.0.0.4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrhoopz
Forum Newbie
Posts: 11
Joined: Tue Feb 06, 2007 1:35 pm

Sessions/Caching problem with Firefox 2.0.0.4

Post by mrhoopz »

I'm been having some problems with sessions, and I'm not sure what's going on. Everything has worked fine while I've been developing my site, but I just put it up on my department's web site (I work for a university) and I experienced some problems when trying to use it from home.

Without going into a ton of detail, sessions aren't working properly. It seems like Firefox is loading cached pages one time and not doing it the next. I'll perform some actions which should reset my sessions but the result uses the previous action's sessions instead. If I repeat, it will then work. But the same problem will occur the next time.

What's more, this is only happening at my apartment when using Firefox. IE works. I've tried using Firefox at a friend's place and it is fine.

So I'm thinking this may be a proxy thing, maybe? I would like to ensure that pages are never cached, since they are dynamically generated php anyways. I have control over the Apache and PHP 5 config files on the server, so if there's something I can do with those, that would be pretty easy.


Sorry if I'm being vague on the problem, I'm just not sure what could be causing a problem like this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It sounds proxy related.

header() can set caching headers.
mrhoopz
Forum Newbie
Posts: 11
Joined: Tue Feb 06, 2007 1:35 pm

Post by mrhoopz »

Well, I found a fix. Before, I was using some javascript to redirect the user after they submitted a form.

Code: Select all

if($_POST['submit']){
     $_SESSION = $_POST['searchCriteria'];
     _js("location.href = 'nextPage.php'");  //my javascript function
}
For some reason, the session variable would not get set every time. To fix this, I put a 100 ms delay in before the javascript redirection, so that the session would be sure to set itself.

Code: Select all

if($_POST['submit']){
     $_SESSION = $_POST['searchCriteria'];
     _js("SetTimeout('location.href=nextPage.php',100)");  //my javascript function
}
It now works fine, except I'm not too thrilled about the way I solved it. I'm still not sure exactly what is going on, but I guess the client is executing the javascript before the session updates and thus, the session doesn't update at all.

Any ideas on what is actually happening and if there is a more elegant way to solve it? thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Read the link I provided previously.
mrhoopz
Forum Newbie
Posts: 11
Joined: Tue Feb 06, 2007 1:35 pm

Post by mrhoopz »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I did read it, and I'm doing this before each page load.

Code: Select all

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

The problem wasn't fixed, however, until I put the delay in there. Is there something I have to do in the php.ini in addition to this?

Also, I forgot to mention, that it must not have been a proxy issue, because I was able to duplicate the error by opening two windows at the same time and submitting forms in each simultaneously.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The link provides information on redirection too.
mrhoopz
Forum Newbie
Posts: 11
Joined: Tue Feb 06, 2007 1:35 pm

Post by mrhoopz »

Thanks. The following code fixed things for me without using that ugly javscript delay.

Code: Select all

session_write_close();
header("Location: nextPage.php");

I found this, of course, in the link you provided for me. Sorry that you had to tell me three times :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You should also be made aware that standards compliance requires a full URL to be given for any header based redirection.
Post Reply