当前位置: 首页 > 知识库问答 >
问题:

试图在同一页上显示错误消息

郑茂勋
2023-03-14

这只是为了漏洞测试的目的

只是为了找到克服XSS攻击的方法

如果textbox字段为空,我将尝试显示错误消息。

但是当我单击submit按钮时,它只在另一个(db_connection.php)页面上显示错误消息,尽管它没有将数据插入到我的数据库中。我希望它在与表单相同的页面上显示错误消息。

这是我的index.php

<html>
    <head>
        <meta charset="UTF-8">
        <title>BadStore.net - Sign our Guestbook</title>
    </head>
    <body>
        <?php
  
        ?>
        <td width="615">
      <table cellspacing="0" cellpadding="0" width="614" border="0">
        <tbody>
            <tr>
                <td bgcolor="#333333"></td>
            </tr>
        </tbody>
      </table>
      <table cellspacing="0" cellpadding="0" width="614" border="0">
        <tbody>
            <tr bgcolor="#ecece0"></tr>
       
            <tr bgcolor="#333333"></tr>
        </tbody>
      </table>
     
     
            <h1>Sign our Guestbook!</h1>
            <hr><p>Please complete this form to sign our Guestbook.  The email field is not required, but helps us contact you to respond to your feedback.  Thanks!</p><p></p><hr>
   <form method="post" action="db_connection.php">
            <table border="0" cellpadding="10">
        
        <tbody>
            <tr>
                <td>Your Name:</td> <td><input type="text" name="name" size="30"></td>
            </tr>
            <tr>
                <td>Email:</td> <td><input type="text" name="email" size="40"></td>
            </tr>
            <tr>
                <td valign="TOP">Comments:</td> 
                <td><textarea name="comments" cols="60" rows="4"></textarea></td>
            </tr>
        </tbody>
    </table>
        <hr>
        <center><input type="submit" name="submit" value="Add Entry">  <input type="reset"></center></font></td>
        </form>

    </body>
</html>

这是我的db_connection.php

<?php
 $dbhost = "localhost";
 $dbuser = "root";
 $dbpass = "";
 $db = "xss";
 $conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db);
echo "<a href=\"javascript:history.go(-1)\">GO BACK</a>";
 if(isset($_POST['submit']))
        {
     if(!empty(($_POST['name'])) && !empty(($_POST['email'])) && !empty(($_POST['comments'])))
     {    
            $Name= htmlspecialchars($_POST['name']);
            $Email=htmlspecialchars($_POST['email']);
            $Comments=htmlspecialchars($_POST['comments']);
            
            $result="INSERT into form(Name,Email,Comments) values('$Name','$Email','$Comments')";
            $run = mysqli_query($conn, $result) or die("Connect failed: %s\n". $conn -> error);
            
     }
     else{
         echo "Please fill in all the information!";
     }
        }
        mysqli_close($conn);
?>
 
        
<?php


 $dbhost = "localhost";
 $dbuser = "root";
 $dbpass = "";
 $db = "xss";
 $conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db);


$sql = "Select * from form";
$abc = mysqli_query($conn,$sql);
?>      
        <table align="center" border="1px" style="width:600px; line-height:40px;"> 
    <tr> 
        <th colspan="4"><h2>Guestbook</h2></th> 
        </tr> 
              <th> No </th> 
              <th> Name </th> 
              <th> Email </th> 
              <th> Comments </th> 
              
        </tr> 
        
        <?php while($rows=mysqli_fetch_assoc($abc)) 
        { 
        ?> 
        <tr> <td><?php echo $rows['No']; ?></td> 
                <td><?php echo $rows['Name']; ?></td> 
        <td><?php echo $rows['Email']; ?></td> 
        <td><?php echo $rows['Comments']; ?></td> 
        </tr> 
    <?php 
               } 
                mysqli_close($conn);
          ?> 
</table> 

共有1个答案

罗和煦
2023-03-14

您可以将required添加到中,这样您就不必检查并显示错误消息(请填写所有信息!)在另一页中:

对于数据库错误消息,如果要将其显示在与将代码移动到其中的同一页上,请如下所示:

<?php
 $dbhost = "localhost";
 $dbuser = "root";
 $dbpass = "";
 $db = "xss";
 $conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db);
echo "<a href=\"javascript:history.go(-1)\">GO BACK</a>";
 if(isset($_POST['submit']))
        {
        
            $Name= htmlspecialchars($_POST['name']);
            $Email=htmlspecialchars($_POST['email']);
            $Comments=htmlspecialchars($_POST['comments']);
            
            $result="INSERT into form(Name,Email,Comments) values('$Name','$Email','$Comments')";
            $run = mysqli_query($conn, $result) or die("Connect failed: ". $conn -> error);
            
     header('Location: db_connection.php');
        }
        mysqli_close($conn);
?>

<html>
    <head>
        <meta charset="UTF-8">
        <title>BadStore.net - Sign our Guestbook</title>
    </head>
    <body>
        <?php
  
        ?>
        <td width="615">
      <table cellspacing="0" cellpadding="0" width="614" border="0">
        <tbody>
            <tr>
                <td bgcolor="#333333"></td>
            </tr>
        </tbody>
      </table>
      <table cellspacing="0" cellpadding="0" width="614" border="0">
        <tbody>
            <tr bgcolor="#ecece0"></tr>
       
            <tr bgcolor="#333333"></tr>
        </tbody>
      </table>
     
     
            <h1>Sign our Guestbook!</h1>
            <hr><p>Please complete this form to sign our Guestbook.  The email field is not required, but helps us contact you to respond to your feedback.  Thanks!</p><p></p><hr>
   <form method="post" action="index.php">
            <table border="0" cellpadding="10">
        
        <tbody>
            <tr>
                <td>Your Name:</td> <td><input type="text" name="name" size="30" required></td>
            </tr>
            <tr>
                <td>Email:</td> <td><input type="text" name="email" size="40" required></td>
            </tr>
            <tr>
                <td valign="TOP">Comments:</td> 
                <td><textarea name="comments" cols="60" rows="4" required></textarea></td>
            </tr>
        </tbody>
    </table>
        <hr>
        <center><input type="submit" name="submit" value="Add Entry">  <input type="reset"></center></font></td>
        </form>

    </body>
</html>
 类似资料:
  • @将有效的打印信息发送到控制台,但不发送到页面 当我的字段有错误@Valid print info到控制台时,为什么不在第页? 字段hotelName上的对象formData中的字段错误:拒绝的值[];代码[Size.formData.hotelName, Size.hotelName, Size.java.lang.String, size];参数[org.springframework.con

  • 我在Tomcat 8.x web服务器上使用JAAS和基于表单的web身份验证。用户在尝试登录时被拒绝访问的原因有很多: 无效的用户名 密码无效 在数据库中没有帐户 数据库中的帐户未激活 数据库中的帐户没有必需的角色 等…… 在我的LoginModule中,我检查所有这些条件以及更多条件,如果不允许用户访问web应用程序,就会抛出LoginException。JAAS似乎捕捉到了抛出的LoginE

  • 我有一个表单输入字段,如果用户尝试在空时提交,则显示错误,但我也想显示不同的错误消息,即输入不是唯一的,我目前有这个 这是MUI v4

  • 问题内容: 我正在使用Spring Security。我想显示登录错误消息,例如登录失败或帐户被锁定。如何在登录页面上显示此类消息? 问题答案: 只需配置为,然后从该servlet设置属性即可,例如 并将此请求转发到登录页面。 或提供 如 检查jsp上的参数 并有条件地打印消息

  • 问题内容: 我正在使用Codeigniter,而不是错误消息,我只是得到一个空白页。有什么方法可以显示PHP错误消息吗?当我没有反馈时很难调试。 我的环境是带有Apache的Ubuntu。 问题答案: 由于到目前为止,没有一种解决方案对您有用,请尝试以下一种方法: 这明确地告诉PHP 显示 错误。某些环境可以默认禁用此功能。 这是我的环境设置的样子:

  • 我试图显示与Html文件位于同一文件夹中的静态图像,但似乎无法获得正确显示的正确路径。我正在开发的应用程序还包括一个从数据库获取数据的java后端,我使用HTML和javascript在前端显示它,整个应用程序作为插件在Web服务器上运行。图像和Html文件都位于此处: Web应用程序的URL路径是: <代码>https://staging.com/jira/secure/SchedulerAct