【发布时间】:2018-11-21 16:03:00
【问题描述】:
header() 中有问题。我知道它必须在任何 html 代码之前,但是用它来替换它,以便它重定向到另一个 url。
这是代码(index.php):
<!DOCTYPE html>
<html lang="en">
<head>title</head>
<body>
<?php
$count = 1;
if ($count > 0) {
header("Location:list.php?incluided");
} else {
header("Location:list.php?error");
}
?>
<body>
<html>
我该如何替换它?谢谢。
解决办法,添加javascript并删除header():
<!DOCTYPE html>
<html lang="en">
<head>title</head>
<body>
<?php
$count = 1;
if ($count > 0) {
print '
<noscript>
<meta http-equiv="refresh" content="0;>
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
{
document.write("redirecting...");
var referLink = document.createElement("a");
referLink.href = url;
document.body.appendChild(referLink);
referLink.click();
}
else { window.location.replace("list.php?incluided"); } // All other browsers
</script>
';
} else {
print '
<noscript>
<meta http-equiv="refresh" content="0;>
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
{
document.write("redirecting...");
var referLink = document.createElement("a");
referLink.href = url;
document.body.appendChild(referLink);
referLink.click();
}
else { window.location.replace("list.php?error"); } // All other browsers
</script>
';
}
?>
<body>
<html>
【问题讨论】:
-
完全不清楚你想问什么。你想在这里“替换”什么?用什么?如果您说您知道在标头调用之前不应该创建任何输出,那么您为什么要显示不遵循该原则的代码?
-
你可以在里面回显 JavaScript window.location if else
-
@DineshBelakare - 我禁用 JavaScript ;)
-
那你别无选择,只能使用php重定向。
标签: php