Page 1 of 1

Why doesn't Refreshing the browser rerun PHP code?

Posted: Mon Jul 27, 2009 8:03 pm
by Simnia
The way I edit, run, and test PHP code is to edit it in Notepad, then pull up the web page (in PHP or HTML) in Internet Explorer to see if it's doing what I want. I have Notepad and IE running at the same time. So far I've been merely refreshing the IE browser screen whenever I want to rerun my PHP program, but tonight I ran into a scary experience that suggests I may be doing something very wrong. I was unable to get a program working all day, I tried running a different program finally, gave up on the second program, came to this forum to post my first (nonworking program), then suddenly when I came back to the first program, it was working! Whew, I wasted a whole day, for what?! Have I been doing something fundamentally wrong?

I noticed that it didn't help when I went to Internet options to erase history, cookies, passwords, everything--I got the same results after a browser refresh--but when I hit Return after the URL in the browser window I noticed that the program seemed to reset everything whereas if I just refreshed the program would seem to just be stuck on the same erroneous results from the previous run. So I guess I won't get stuck with that ineffectual refresh problem anymore, but it would be nice to know why refresh doesn't work. I'm using Windows XP with XAMPP.

The code I was running read a text file line by line, sent each line into a MySQL database, closed the text file and database, and the whole thing was initiated by a single Submit button. No textual inputs, almost no logic. Fairly simple. Could some submit flags or file flags have been set and not cleared somehow? It was the submit button and reentry into the same PHP program that was throwing me off, since none of my "isset" checks for flags seemed to work.

Re: Why doesn't Refreshing the browser rerun PHP code?

Posted: Mon Jul 27, 2009 8:15 pm
by jackpf
Probably something stupid IE does with it's cache.

Try another browser. Why the <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> you use IE anyway is beyond me. No web developer should stoop so low :P

Re: Why doesn't Refreshing the browser rerun PHP code?

Posted: Tue Jul 28, 2009 12:49 am
by Cirdan
I think if you press shift-F5 it will really reload the page instead of loading from the cache.

Re: Why doesn't Refreshing the browser rerun PHP code?

Posted: Tue Jul 28, 2009 7:31 am
by alex.barylski
Use the following at the start of every script or store in a central config or if using a framework like Zend front controller pre-plugin:

Code: Select all

     
$response->setHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
$response->setHeader('Last-Modified', gmdate('D, d M Y H:i:s').' GMT');
$response->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
$response->setHeader('Cache-Control', 'post-check=0, pre-check=0');
$response->setHeader('Pragma', 'no-cache');
Replace $response object with call to generic header() if your not using a framework.

This should tell any browser the request is not to be cached on the client side of things, so any changes made on the server are sent back to browser exactly as intended. Caching issues are always a (*&(^& and hard to figure out.

Cheers,
Alex

Re: Why doesn't Refreshing the browser rerun PHP code?

Posted: Tue Jul 28, 2009 2:08 pm
by Simnia
Thanks for all of your suggestions. I'll give them all a try when I get a chance. Right now I'm just rushing to get this program done by Friday.

I use IE because Firefox stopped working on my home PC for some unknown reason, which caused me grief, so I got in the habit of using IE instead. The only thing I know for sure wrong with IE is that somebody said IE makes it easy to track my web page visits--poor security. But I haven't seen details or proof of that

Re: Why doesn't Refreshing the browser rerun PHP code?

Posted: Tue Jul 28, 2009 6:31 pm
by Doug G
As a general comment, don't design a web application that relies on a user issuing a refresh/reload in their browser. There are too many potential problems with reliability.

And there is nothing wrong with IE, IE won't leak your security any more than Firefox will leak your security. And it's known that Firefox will leak your memory ultimately causing computer crashes, and the Firefox development team apparently has no interest in fixing this problem.

Re: Why doesn't Refreshing the browser rerun PHP code?

Posted: Tue Jul 28, 2009 9:59 pm
by Cirdan
Doug G wrote:And there is nothing wrong with IE
Except for the fact that it doesn't adhere to the standards

Re: Why doesn't Refreshing the browser rerun PHP code?

Posted: Wed Jul 29, 2009 7:11 am
by jackpf
If you design websites for IE, you'll get into the habit of using hacks that mess up how your site looks in every other browser.

I find it better to design a page for a real browser, and then once it looks good, start the hacks for IE, but do so in IE conditional comments.