IE7和IE8中站点的意外重定向


Unexpected redirection of site in IE7 and IE8

我以前试过这个问题,但没有提供足够的信息,所以这里有更多的细节。我在一个托管网站上有一个页面,要求访问者在表单中输入一个编码字符串。提交后,代码会生成一个文件名,并从文本文件中获取一些简单的数据。

在FF和Safari中一切都很好,但在internet explorer 7和internet explorer 8中测试时,提交后,访问者会重定向到网站主页。

同样的意外重定向也发生在网站的其他地方。我希望如果我能在这里隔离这个问题,我就能修复其他实例。

这是代码:

<?php
    session_start();
    ob_start;
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Advisor Survey - 2012 Predictive Questions</title>
<link href="css/surv_ver2.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/s_table.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
    <div id="header">

    </div> <!-- close header -->
    <div id="wrapper">
        <div id="mid_cont">
            <div id="mid_left">

            </div> <!-- close mid_left -->
            <div id="mid_col">
                <div id="mid_col_inner">
                <h2 class="p_head">Scoring Details</h2>
                <p class="p_text">Want to learn more about how your site compares to others in your market? We employed tools to evaluate your web site from a high-level marketing perspective.</p>
                <p class="p_text">All of our sample tests mimic search engine functionality. Check our site to see where your score falls in the overall Denver market.</p>

                </div> <!-- close mid_col_inner -->

            </div> <!-- close mid_col -->
            <div id="mid_center">
                <div id="top_cent">
                    <img src="images/revenue_subhead.png" />
                </div> <!-- close top_cent -->
                <div id="mid_cent">
                    <p class="mid_col_text">Enter the code (no punctuation or spaces) from our communication with you to see your score.</p>

                </div> <!-- close mid_cent -->
                <div id="bot_cent">
                    <div id="bot_left">
                        <form method="POST" action="<?php $_SERVER['PHP_SELF'] ?> " />
                        <label id="label2">Enter code: </label>
                        <input type="text" name="code" id="code" />

                        <input type="submit" name="submit" id="code_submit" />
                        </form>
                    </div> <!-- close bot_left -->
                    <div id="bot_right">
                        <?php 
                            if (($_POST['submit']) and (empty($_POST['code']))) {
                                echo "<br/><br/>";
                                print "<p class='"spl_p'"> Please select choice!</p>";
                            }
                            if (!empty($_POST['code']))  {
                                $response = $_POST['code'];
                                echo $response;
                                $test_name = $response . ".txt";
                            $test_name = "../id_advisors/$test_name";
                            if (!file_exists($test_name)) {
                                echo "Please re-enter code!";
                                exit();
                            }
                            }
                            if (!empty($_POST['code'])) {
                            echo $test_name;
                            // read in the details of the file for each firm
                            $pointer = fopen("../id_advisors/$test_name", "r");
                            $data_line = fgets($pointer, 1096);
                            fclose($pointer);
                            $file_array = explode("'t", $data_line);
                            foreach ($file_array as $item) {
                            $item = $file_array;

                            $firm_name = $file_array[0];
                            $mkt_id = $file_array[1];
                            $site_id = $file_array[2];
                            $score = $file_array[3];
                            $pages = $file_array[4];
                            $traffic_rank = $file_array[5];
                            $in_links = $file_array[6];
                            $start_date = $file_array[7];
                            }
                            }
                            ?>
                            <table id="form_2" cellpadding="-3">
                            <tr><td width="100">Firm name: </td><td><input type="text" name="f_name" id="f-name" value="<?php echo $firm_name; ?>" /></td></tr>
                            <tr><td width="100">Market ID: </td><td><input type="text" name="mkt" id="mkt" value="<?php echo $mkt_id; ?>" /></td></tr>
                            <tr><td width="100">URL : </td><td><input type="text" name="url" id="url" value="<?php echo $site_id; ?>" /></td></tr>
                            <tr><td width="100">Score: </td><td><input type="text" name="score" id="score" value="<?php echo $score; ?>" /></td></tr>
                            <tr><td width="100">Index pages: </td><td><input type="text" name="pages" id="pages" value="<?php echo $pages; ?>" /></td></tr>
                            <tr><td width="100">Traffic: </td><td><input type="text" name="traff" id="traff" value="<?php echo $traffic_rank; ?>" /></td></tr>
                            <tr><td width="100">Inbound links: </td><td><input type="text" name="i_links" id="i_links" value="<?php echo $in_links; ?>" /></td></tr>
                            <tr><td width="100">Test date: </td><td><input type="text" name="t_date" id="t_date" value="<?php echo $start_date; ?>" /></td></tr>
                            </table>
                    </div> <!-- close bot_right -->
                </div> <!-- close bot_cent -->
            </div> <!-- close mid_left -->
            <div id="mid_right">

            </div> <!-- close mid_left -->
        </div> <!-- close mid_cont -->
        <div id="footer">

        </div> <!-- footer -->
        <div id="sub_foot">
            <p>Copyright 2012  |  Lighthouse Pacific Group, LLC  -  All Rights Reserved</p>
        </div> <!-- close sub_foot -->
    </div> <!-- close wrapper -->
</body>
</html>

您在创建FORM元素的同一行关闭它:

 <form method="POST" action="<?php $_SERVER['PHP_SELF'] ?> " />

将其更改为:

<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?> ">

我不确定这会具体解决你的重定向问题,但我知道如果你不解决这个问题,它会导致你的表单提交出现一些问题。

编辑

好吧,我第一次忽略了这个问题,这里是修复方法,更改上面列出的同一行代码,但包括echo。。。

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

或者简化:

<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">