English 中文(简体)
PHP header("Refresh") problems
原标题:

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?

最佳回答

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.

问题回答

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.

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

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




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签