Forum Moderators: open

Message Too Old, No Replies

Meta Refresh: Is it Safe?

meta refresh compatibility

         

Tehuti

12:41 am on Nov 12, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



I need to redirect after a short delay of about ten seconds. I am going to use a meta refresh, thus:

<head>
<meta http-equiv="refresh" content="10; url=http://www.mysite.com">
</head>

Are meta refreshes safe? In other words, are they compatible with all major browsers? Might it not work in some instances?

I know that redirects can be switched off in Opera. Are there any other drawbacks to using them?

D_Blackwell

1:02 am on Nov 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Safe enough I think. Other opinions will vary. The reason for the redirect will impact how to best redirect. Is an instant 301 a better choice? Google will index both both pages. Is that an issue? There are bunches of scripts for redirects.

It can be done with PHP, .asp, AJAX. I still have a couple few abandoned sites that use the meta redirect on the original index page (edited to avoid duplicatation (the rest of the site dumped/moved.) Set for 15 seconds so that users can read that the old site has been moved, and includes a link, so that they don't have to wait and just click right away.

Sometimes not a bad idea for the old page to be indexed for a long time if it ranks highly. Gives time for the new site to catch up.

Tehuti

2:34 am on Nov 12, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks, D_Blackwell.

It has to be a delayed redirect, which is why I'm using a meta refresh. I've heard that it's safer to do the delayed redirect with PHP. Is that so?

rocknbil

7:13 pm on Nov 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All browsers can shut off meta-refresh, most users don't.

The advantage to doing a "delayed redirect" with a server side language is you have the ability to generate appropriate headers, if you need them. The reasons for needing a delay may not require it though, for example, if someone clicks download and you redirect to a page for instruction/usage, you won't need special headers, a meta refresh is fine.

Another example, I only use meta-refresh for say, index.html an images directory if I don't have the ability to disable directory indexing and don't want the casual visitor snooping around. In that case, there's no links to it and I don't really care what the S.E.'s do with that directory.

D_Blackwell

1:49 am on Nov 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've heard that it's safer to do the delayed redirect with PHP. Is that so?

No, not IMO. As rocknbil pointed out, the meta will rarely be a problem

It can be done with JavaScript, and most people do not disable that either.

The code below should work with PHP. It will display the page for 15 seconds, and then redirect. Does have the very slight, but probably not worthwhile, advantage that it is server side and will execute whether the user likes it or not.

<?php
header("refresh: 15; url=http://www.example.com");
?>

Tehuti

2:38 am on Nov 13, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



D_Blackwell and rocknbil, thank you both for your replies.

I ended up using a PHP refresh, like the one in D_Blackwell's last reply. It seems to be working fine.

Please let me tell you exactly why I need the redirect, so you can tell me if I am using the right method . . .

Imagine a simple Web site with 3 pages. Visitors click to go from Page 1 to Page 3. Before they get there, I need to install a cookie, so I first send them to Page 2. On Page 2, I install the cookie, before redirecting them to Page 3.

The cookie is loaded onto visitors' computers via the source attribute of an image element, thus:

<img src="URL" alt="" width="1px" height="1px" />

It is not installed unless the image element has fully downloaded. That's why I wait 10 seconds before redirecting.

To keep the download speed of Page 2 to a minimum, it's as plain as possible. It has no other images, and has very little markup and content. All it includes is a short message saying "Please wait. Loading order form . . .", plus a hyperlink to Page 3, just in case the redirect doesn't work.

Since I pay for my visitors, and since the cookie MUST be installed before the visitor hits Page 3, the whole process needs to be as compatible as possible.

With that in mind, please tell me . . . Would you have done it differently?

rocknbil

7:23 pm on Nov 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The cookie is loaded onto visitors' computers via the source attribute of an image element, thus:

I don't understand this. :-) If you need to set a cookie, why don't you just set the cookie on page 1?

Load it dynamically in index.php

setcookie ($cookiename, $new_id, time()+$cookietime, '/');

or via Javascript

document.cookie = name + "=" + escape(value) +
";expires=" + expires_date.toGMTString() +
";path=" + path);

Tehuti

7:11 pm on Nov 14, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks, rocknbil.

I can't set this particular cookie myself. It has to be set by another site. As far as I am aware, this can only be achieved by loading the other site in a hidden frame, or by including an image element with the other site's URL set as the value of the source attribute:

<img src="URL" alt=" " width="1" height="1" />

While downloading my page, the browser follows the URL and acts on the HTTP headers of the other site, which sets the cookie.