dongshai2022 2011-10-08 09:34 采纳率: 100%
浏览 24
已采纳

PHP - 在MSIE中带#中断的头重定向

When redirecting with header() after a form upload, if there is # in the redirect, it disappears in MSIE, but works properly in other browsers. I've made the following simple script as an example:

<?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>

In Firefox and other browsers it redirects to http://localhost/#someanchor

In MSIE it redirects to http://localhost (loses the anchor)

If I remove the file input, then it works in MSIE as well! (but I need the file upload)

I could work around it with Javascript but maybe there is something I'm missing here?

  • 写回答

3条回答 默认 最新

  • doulai6469 2011-10-08 10:53
    关注

    This is one of the rare cases where IE stricly implements the RFC. In the Location-header, you must send an 'absolute uri', as defined here:

    absoluteURI = scheme ":" ( hier_part | opaque_part )

    So, no fragment (#).

    See this question for a more extensive answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程