Why doesn't Refreshing the browser rerun PHP code?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Simnia
Forum Newbie
Posts: 9
Joined: Tue Jul 07, 2009 5:37 pm

Why doesn't Refreshing the browser rerun PHP code?

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

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

Post 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
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

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

Post by Cirdan »

I think if you press shift-F5 it will really reload the page instead of loading from the cache.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

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

Post 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
Simnia
Forum Newbie
Posts: 9
Joined: Tue Jul 07, 2009 5:37 pm

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

Post 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
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

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

Post 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.
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

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

Post by Cirdan »

Doug G wrote:And there is nothing wrong with IE
Except for the fact that it doesn't adhere to the standards
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

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

Post 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.
Post Reply