在表单上传之后使用header()重定向时,如果重定向中有#,它将在MSIE中消失,但在其他浏览器中正常工作。我做了以下简单的脚本为例:PHP - 在MSIE中带#个标头的标题重定向
<?php
if (isset($_REQUEST["description"])) {
$location = "http://localhost/#someanchor";
header("Location: $location");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHP header redirect with #</title>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER["PHP_SELF"]?>">
<div>
Description <input type="text" name="description" /><br /><br />
File <input type="file" name="uploadfile" /><br /><br />
<input type="submit" />
</div>
</form>
</div>
</body>
</html>
在Firefox和重定向到http://localhost/#someanchor
在MSIE它重定向到http://localhost其他浏览器(失去锚)
如果我删除文件输入,那么它也可以在MSIE中使用! (但我需要文件上传)
我可以用Javascript解决它,但也许有什么我在这里失踪?
我试图解决它,但无法弄清楚:P也许你可以用别的东西取代锚点,像一些获取请求?顺便说一句,使用'$ _SERVER [“PHP_SELF”]'是很危险的。 Google'php_self危险'了解更多信息。 – Olli
谢谢,这只是一个简单的例子,我通常不使用PHP_SELF,但是当我这样做时,我会确保通过htmlspecialchars。 –
好的,很好。但是,你可以使用GET请求来解决问题,而不是使用锚? – Olli