【问题标题】:HTML Formular redirects to XAMPP localhost Home-PageHTML 公式重定向到 XAMPP 本地主机主页
【发布时间】:2011-09-16 08:01:59
【问题描述】:

所以,我又遇到了另一个问题-.-'

我编写了我自己的 php/html 脚本来让步并将数据从表单传递到数据库。一开始它奏效了。不知何故,几天后它开始将我重定向到 XAMPP localhost 主页 (http://localhost/xampp/)。我不知道为什么:/

我的网站如下所示:

  • index.php
    • 所有其他脚本(通过 Switch-case)
    • 包括我的留言簿脚本(没有开关盒!)它总是在那里!

这是我的“addguestbook.php”的样子:

   <?php

...database stuff...

if ($_SERVER['REQUEST_METHOD'] == 'POST'){

    $name = $_POST['name'];
    $email = $_POST['email'];
    $website = $_POST['website'];
    $comment = $_POST['comment'];
    $datetime = date("l, jS M Y, g:i a"); //date time

    // Connect to server and select database.
    mysql_connect($host, $username, $password)or die("cannot connect server: ".mysql_error());
    mysql_select_db($db_name)or die("cannot select DB: ".mysql_error());

    $sql="INSERT INTO ".$tbl_name."(id, name, email, website, comment, datetime)VALUES('".$post_id."', '".$name."', '".$email."', '".$website."', '".$comment."', '".$datetime."')";
    $result=mysql_query($sql);

    mysql_close();

    header('Location: http://'.$hostname.$path.'/index.php' . $get, true, 303);
}?>

<form action="index.php<? echo $get; ?>" method="post">
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="guestbookFormCell" colspan='2'><input
                class="guestbookInputFieldText" name="name" type="text"
                value="Name *" size="40" maxlength="30" /></td>
        </tr>
        <tr>
            <td class="guestbookFormCell" colspan='2'><input
                class="guestbookInputFieldText" name="email" type="text"
                value="E-Mail (won't become displayed)" size="40" maxlength="40" />
            </td>
        </tr>
        <tr>
            <td class="guestbookFormCell" colspan='2'><input
                class="guestbookInputFieldText" name="website" type="text"
                value="Website" size="40" maxlength="50" /></td>
        </tr>
        <tr>
            <td class="guestbookFormCell" colspan='2'><textarea
                    class="guestbookInputFieldText" name="comment" cols="37" rows="5">Comment *</textarea>
            </td>
        </tr>
        <!-- 
        <tr>
            <td>CAPTCHA</td>
        </tr>
         -->
        <tr>
            <td><button class="guestbookFormCell guestbookButton" type="submit"
                    name="submit">
                    <span class='guestbookButtonText'>Send</span>
                </button></td>
            <td><button class="guestbookFormCell guestbookButton" style="float:right;"type="reset"
                    name="reset">
                    <span class='guestbookButtonText'>Reset</span>
                </button></td>
        </tr>
    </table>
</form>

在 index.php 中:

                $get = "?mod=home";

此脚本用于多种用途:页面的整体留言簿以及单个帖子和图片/相册上的 cmets。

PS:由于某种原因,我不能在线程的开头写你好:/如果这太粗鲁了,我很抱歉!

PSS:出错了。

相当愚蠢:)

我只是忘记了论坛实际上是重定向到(在这种情况下)根目录中的 index.php。这意味着 Xampp/htdocs/index.php。

我只是要修复链接,我很好 -.-'

【问题讨论】:

  • PS: i couldN't write hello at the beginning of the thread, for some reason :/ If that came over rude, i'm sorry! 今日笑话... :)
  • “你好”这个词是不必要的。见meta.stackexchange.com/questions/92382/…
  • +1 当天的笑话

标签: php html forms redirect xampp


【解决方案1】:

只需编辑或删除原始 index.html 并删除以下行

<meta http-equiv="refresh" content="0;url=/xampp/">

如果你也清理你的缓存最好,因为你的浏览器会强制加载每一个新的。

内政

编辑:你并不孤单:why-does-my-xampp-installation-auto-redirect-to-http-localhost-xampp

【讨论】:

    【解决方案2】:

    很高兴您确实找到了问题所在,因为我实际上无法理解您的脚本是如何工作的,但是,在分配 $name、$email、$website 等时,您必须使用 mysql_espace_string()。否则,用户可能会注入恶意代码并访问整个 SQL 表。

    $name = mysql_escape_string($_POST['name']);
    $email = mysql_escape_string($_POST['email']);
    $website = mysql_escape_string($_POST['website']);
    $comment = mysql_escape_string($_POST['comment']);
    $datetime = date("l, jS M Y, g:i a"); // Escaping the string is not necessary here.
    

    (抱歉有任何语言错误:我不是以英语为母语的人。)

    【讨论】:

    • 更好的是,使用参数化查询(通过 PDO)。
    猜你喜欢
    • 2017-05-16
    • 2020-06-24
    • 2018-12-29
    • 2020-07-24
    • 2017-09-18
    • 2017-06-28
    • 2020-04-26
    • 2014-02-17
    • 2012-05-03
    相关资源
    最近更新 更多