我有page1.php
代码:
<form action="/redirect.php" method="POST" target="_blank">
<input name="destination" type="hidden" value="a"/>
<input type="submit" value="Click here"></form>
这是redirect.php
:
<?php
$url = "http://www.default.com";
if(isset($_POST['destination'])){
switch ($_POST['destination']) {
case "a":
$url = "http://www.domain1.com";
break;
case "b":
$url = "http://www.domain2.com";
break;
default:
$url = "http://www.default.com";
}
}
header( "refresh:1;url=$url" );
?>
<!doctype html>
<html>
<head>
</head>
<body>
<div>Redirecting, Please wait</div>
</body>
</html>
我已经以这种方式创建了重定向页面,因为它对我来说很重要,它会加载并显示某些内容,而不是直接重定向(因此,它会产生200个代码,而不是302代码)。 / p>
但是,仅在Chrome和Safari上,重定向的标题包含有关引荐网址的信息,即redirect.php
,因此,domain1.com
的所有者将知道该访问者来自mydomain.com/redirect.php
。
但是在IE和FF上,标题中的引用者为空。造成这种不同行为的原因是什么?如何修复它以使它们具有相同的引荐信息?
答案 0 :(得分:0)
您可以尝试:
header("Location: ".$url."");
答案 1 :(得分:0)
工作示例(在FF 27.0.1上试用):
档案page1.php
:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Starting page</title>
</head>
<body>
<form action="redirect.php" method="post">
<input type="hidden" name="destination" value="a">
<input type="submit" value="Click here">
</form>
</body>
</html>
档案redirect.php
:
<?php
$url = "http://www.default.com";
if(isset($_POST['destination'])){
switch ($_POST['destination']) {
case "a":
$url = "http://www.domain.com";
break;
case "b":
$url = "http://www.examples.com";
break;
default:
$url = "http://www.example.com";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Landing page</title>
</head>
<body>
<div>Redirecting, Please wait</div>
<script>
window.onload = function() {
setTimeout(function(){
window.location = '<?php echo $url;?>';
}, 4000);
};
</script>
</body>
</html>
工作原理:点击Click here
上的page1.php
按钮后,会发送帖子数据并选择域http://www.domain.com
。使用javascript,在窗口加载后4秒后,浏览器会将用户重定向到http://www.domain.com
。我已经在Firebug
中看到了引用标题,并且已经发送了它们。
答案 2 :(得分:-1)
混淆。重定向和页面刷新不一样。还有更多 - 并非所有浏览器都支持刷新标题。