homepage Welcome to WebmasterWorld Guest from 50.17.27.205
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
clearing header info
sssweb




msg:4474699
 5:25 pm on Jul 11, 2012 (gmt 0)

I have a simple script that does page redirects based on a $_GET variable passed to it. It works fine the first time it runs for a particular value of the var. But if I change the redirect (or any other scripting) for that value, it won't update. It keeps redirecting to the original page as though I didn't update the script.

I was using:

header( "Location: [url.com",...] '', 301 );

Is the '301' ("Moved Permanently") causing the browser to ignore new requests?

I've since changed it to '307' but maybe it doesn't help since it already ran the 301 once. I've tried clearing my browser cache, and closing & re-opening it, to no avail.

Any ideas?

 

g1smd




msg:4474741
 8:36 pm on Jul 11, 2012 (gmt 0)

Redirect status is cacheable.

Properly delete/clear the browser cache before retesting.


The canonical URL for the root page ends with a trailing slash.

Use example.com in this forum.

sssweb




msg:4474986
 2:23 pm on Jul 12, 2012 (gmt 0)

Thanks - as I said though, the problem continues even after I clear my browser cache...

sssweb




msg:4475049
 4:26 pm on Jul 12, 2012 (gmt 0)

I didn't figure this out, but once I finalized my script, I just changed the variable name to ensure fresh values when processing. It works fine, so unless someone sees some underlying issue, I'll assume it's resolved.

rlange




msg:4475059
 4:39 pm on Jul 12, 2012 (gmt 0)

Hmm... I've had similar problems with Firefox and clearing the browsing history rather than the cache seems to correct it.

-Ryan

sssweb




msg:4479703
 1:17 pm on Jul 28, 2012 (gmt 0)

Thanks rlange - I ran into this problem again today and changing the page name wasn't an option; clearing the cache didn't work, but clearing history did. NOTE FOR IE USERS: be sure to UNcheck 'Preserve Favorites website data in the delete history dialog; it didn't work until I did that.

Seems to me this is a browser bug. If a URL delivers a 'page not found' error, why does the browser repeat the error even when the page has been added and the URL is now valid?

Is there an issue with my HTTP response code as indicated in my first post? As I said, I changed it from '301' to '307', but it still seems to glitch.

g1smd




msg:4479769
 7:25 pm on Jul 28, 2012 (gmt 0)

The 307 is temporary, I'm sure that 301 is what you really require.

sssweb




msg:4479778
 8:22 pm on Jul 28, 2012 (gmt 0)

So why doesn't the browser update when the HTTP status changes?

g1smd




msg:4479785
 8:48 pm on Jul 28, 2012 (gmt 0)

Even though it is "temporary", the response is still cacheable.

sssweb




msg:4479877
 11:02 am on Jul 29, 2012 (gmt 0)

So I should just go with the 301 and if users get a rare page error (say, my server's down or I remove a page then put it back), they're stuck with it until they clear their cache?

rlange




msg:4480582
 2:19 pm on Jul 31, 2012 (gmt 0)

Is there an issue with my HTTP response code as indicated in my first post? As I said, I changed it from '301' to '307', but it still seems to glitch.


Huh... A 307 should cause compliant browsers to keep checking the original URL, which means they should get the redirect destination every time. The only thing I can suggest is to check the response headers your server is sending (I use the "Live HTTP Headers" extension for Firefox). If your server is telling browsers that your 307 redirect can be cached, they'll cache it.

--
Ryan

sssweb




msg:4480615
 5:01 pm on Jul 31, 2012 (gmt 0)

Thanks, I'll look into that.

MaxPowers




msg:4480677
 7:58 pm on Jul 31, 2012 (gmt 0)

header("Cache-Control: nocache");
header("Pragma: nocache");

will work to fix recent FF5/IE9 issues with redirects. The browsers call this a speed implementation (and they are correct), but this issue has wreaked havoc on older sites not setting the cache to ignore the response.

This has fixed a few redirect issues I've seen recently.

sssweb




msg:4480713
 9:42 pm on Jul 31, 2012 (gmt 0)

That looks like what I need. I'll be using it in error processing, so do I put that atop my error page so that the page doesn't keep showing up once the URL becomes valid?

MaxPowers




msg:4480766
 1:39 am on Aug 1, 2012 (gmt 0)

All headers need to be sent before any output to the browser... this includes spaces before the <? in the start of a PHP document or any print/echo commands or any PHP errors sent to the screen. Headers come first.

This is similar to an HTML doc with the 'head' section coming before the 'body' section.

The top is an excellent place to add cache-control headers, but be very certain that there is no output to the browser before the headers are sent or it may generate an error (white screen).

If a page redirects somewhere (possibly in the future), it needs to send the cache control headers before issuing a redirect status of 3xx. Otherwise the redirect may be permanently cached in the newer browsers, even if the page returns later.

If you still experience an issue immediately after implementing this, this is normal with a 'tainted browser'. Clear your cookies and cache, then try the page again. It will no longer be cached in your browser and will no longer be cached in fresh browsers visiting your site.

sssweb




msg:4481042
 6:20 pm on Aug 1, 2012 (gmt 0)

MaxPowers said:
If a page redirects somewhere (possibly in the future), it needs to send the cache control headers before issuing a redirect status of 3xx.

So rather than putting atop the error display page, I should add it to my error processing page, immediately before I redirect to the display page? Like so:

header("Cache-Control: nocache");
header("Pragma: nocache");
header( "Location: http://example.com/error_display.php', '', 301 );
exit;

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved