Jump to content

Why HEADER? Why not META Refresh...


phpSensei

Recommended Posts

From wikipedia about meta refresh:

This is considered by the W3C to be a poor method of redirection, since it does not communicate any information about either the original or new resource, to the browser (or search engine). The W3C's Web Content Accessibility Guidelines (7.4) discourage the creation of auto-refreshing pages, since most web browsers do not allow the user to disable or control the refresh rate.

 

Usually ive used meta refresh in my scripts, so i dont care about "headers already sent". Its a bad method or not, it gives me the result i want.

Link to comment
Share on other sites

i'd say the most useful feature of a meta refresh is that it can be delayed.  for example if you've let someone edit a profile, you can issue a success message that says "Profile successfully edited.  You will be returned to your profile page shortly."  and they will see the new page several seconds later.  often times if you header() immediately to the following page, users will be left wondering whether their edit was successful or not.

Link to comment
Share on other sites

In some ways meta refresh is like a javascript redirect. Users have the ability to disable this as a preference. Header redirects are handled on the server... users can't disable the transfer. As others have mentioned there is a use for some of the meta/javascript methods in that you can delay and send other output before deciding to do the redirect.... can't do this with header.

Link to comment
Share on other sites

I dont think that's what jesirose meant.

 

As MadTechie said, the right tool for the right job. You just need to be aware of the limitations and when meta/javascript will work and when they won't if you're counting on it being enabled for your site to function and someone doesn't you're going to rub your users the wrong way. If using meta/javascript id suggest also adding a link that says... if you aren't automatically redirected click here type of thing.

Link to comment
Share on other sites

"often times if you header() immediately to the following page, users will be left wondering whether their edit was successful or not."

 

That's why you display a success or failure message on the next page.

 

not if you don't want the hassle of sending yet another (relatively useless) request along with the header() redirection in order to flag that a success or error message should be shown.  even though it's not exactly tough to do so, i just find it handier to echo the message where i've accepted and processed the request.

 

but you're right, that's always an option.

 

i personally don't see the harm in using a META refresh as long as you offer the user a link to where it's going anyway (be it to avoid a delay or whatever).

Link to comment
Share on other sites

I personally can't stand the meta refresh. It generates a little to much overhead for a redirect (ie loading a page, refreshing, then loading another page). It can also be disabled.

 

I prefer using headers as this is done and used before any output is sent to the browser. Yes it will throw an error if output is already sent. This is how headers are, it will throw an error if output is sent and you try and set any other data ie user agent, http-status. This is not just the redirect, but all headers in general. Also, bots can pick up on these redirects and know the information from where it came from as well as where it is going.

 

If you have problems using redirect's in the right place, try coding for the better. For instance, after every single POST and processing takes place on my pages, I issue a header redirect. That way on the next page when the person hits refresh, it doesn't repost the data. When the user hits the back button, they are returned to the original form, rather then to the POSTED TO page.

 

If you need help with these things, I highly recomend looking into output buffering.

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.