Forum Moderators: open
<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?
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.
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.
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");
?>
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?
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);
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.