2011-06-16 92 views
9

所以,在这里我有一个问题-.-”HTML公式推重定向到本地主机XAMPP主页页

我编程我自己的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"; 

此脚本用于几个东西:整体gueastbook该页面和单帖&图片/相册的评论。

PS:我无法在线程的开头写出你好,出于某种原因:/如果这个问题过来了,我很抱歉!

PSS:出现错误。

非常愚蠢的:)

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

我只是要解决这个链接,我没事-.-”

+2

'PS:我不能在螺纹的开头写个招呼,因为某些原因:/如果走了过来粗鲁,对不起!'当天的笑话... :) – 2011-06-16 12:25:45

+0

老兄!123456789 – JustBasti 2011-06-16 12:28:16

+0

你忘了'0' – 2011-06-16 12:29:49

回答

0

我很高兴你没有发现是什么问题,因为我不能真正理解你的脚本工作,但是,当分配$ 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. 

(对不起,任何语言的错误:我不是以英语为母语。)

+1

更好的是,使用参数化查询(通过PDO)。 – 2011-11-17 17:06:40

2

只需编辑或删除原单index.html,然后删除以下行

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

最佳会如果你也清理缓存,那么因为你的浏览器预计会加载每一个新的缓存。

编辑:我想你不到独自带着这个问题:why-does-my-xampp-installation-auto-redirect-to-http-localhost-xampp