开发者

PHP header("Refresh") problems

开发者 https://www.devze.com 2022-12-13 15:09 出处:网络
I have some code like: header(\'Refresh: 15; url=\' . $url); This works fine, except when people are visiting this url via Twitter (posted from a Hootesuite client).Apparently, in all browsers othe

I have some code like:

header('Refresh: 15; url=' . $url);

This works fine, except when people are visiting this url via Twitter (posted from a Hootesuite client). Apparently, in all browsers other than IE this works properly. With IE, from the Hootesuite link, this does not refresh properly; a开发者_如何学运维 direct link does.

Why?


I always advocate a combination to avoid problems with the inevitable WebTV user:

  • Header (as you're doing)
  • Meta tag (in the HTML head)
  • Javascript timeout

If the Twitter client is using a link shortener, the type of redirect may be influencing IE in an unanticipated way.


It turns out that, because the URL we're using sets a cookie, and Hootsuite creates a frame, that IE won't trust the third party cookie (our site). So I've added some framebuster code to the page, and triggered it to happen "immediately" if the browser is IE. Code is below:

<meta http-equiv="refresh" content="15;url=<?php echo $url ?>" />
<script type="text/javascript">
var timeout = 1;
if (navigator.userAgent.match(/MSIE/)) { timeout = 1; } else { timeout = 14500; }
setTimeout('if (top != self) top.location.replace(self.location.href)', timeout);
</script>

Maybe this will help some other random user out there some day.


Have you tired setting the location header instead, for example.

$url = "http://www.example.com/";
header("Location: " . $url);
0

精彩评论

暂无评论...
验证码 换一张
取 消