Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我的代码在试图阻止Sql注入时不起作用?_Php_Html_Sql - Fatal编程技术网

Php 为什么我的代码在试图阻止Sql注入时不起作用?

Php 为什么我的代码在试图阻止Sql注入时不起作用?,php,html,sql,Php,Html,Sql,我是一名年轻的开发人员,试图阻止在一个我最初没有自己编写代码的站点上进行Sql注入。我读过很多关于注射和注射背后的理论的文章,但我似乎不能正确理解这一点。在我把头伸进显示器之前,请帮帮我。 谢谢 我的显示器 代码如下: <div id="main"> <div id="header"><? include('site_headergraphics.php'); ?></div> <table width="800" height="100%"

我是一名年轻的开发人员,试图阻止在一个我最初没有自己编写代码的站点上进行Sql注入。我读过很多关于注射和注射背后的理论的文章,但我似乎不能正确理解这一点。在我把头伸进显示器之前,请帮帮我。 谢谢 我的显示器

代码如下:

<div id="main">
<div id="header"><? include('site_headergraphics.php'); ?></div>
<table width="800" height="100%" border="0" cellspacing="0" cellpadding="0" 
class="content">
  <tr>
    <td width="800" valign="top">
      <div style="padding:10px;">


  <? if($_SESSION[$_SESSION['SFIX'].'_owner_id'] == ''){ ?>
  <br><br>
        <form name="balance_login" method="post" action="<? if ($_GET['passthru']){    
?>?passthru=<?= $_GET['passthru'] ?><? } else { ?>?<? } ?>">
      <input name="action" type="hidden" value="login" />
      <table width="780" border="0" cellpadding="5" bgcolor="#FFFFFF">
        <tr>
          <td><table width="780" border="0" cellpadding="5" cellspacing="0" 
bgcolor="#F7C30F" class="body_text">
            <tr>
              <td colspan="3" align="left" class="rightmenu"><?= $passmessage ?><?= 
$specialmessage ?></td>
                </tr>
            <tr>
              <td colspan="2" align="left" valign="top" class="rightmenu">To sign on, 
enter your information below.</td>
                  <td width="412" rowspan="5" valign="top"><p>Welcome to Mediterranean 
Wellness!</p>
                  <p>Ready to join us?  You can <a 
href="index.php?section=payment">GET STARTED here. </a></p></td>
            </tr>
            <tr valign="top">
              <td width="121" align="right" class="rightmenu">Username:</td>
                  <td width="217"><input name="username" type="text" class="body_text" 
id="username" /></td>

                  <!--Added in the prevent SQL code injections-->
                  <?php /*?><?php unset($FindUser);       
                        if(isset($_POST['username']))
                        {
                            $_POST['username'] = 
trim($_POST['username']);
                            if(preg_match('/^[a-
zA-Z0-9^$.*+\[\]{,}]{1,32}$/u', $_POST['username']))
                                $FindUser = 
$_POST['username'];
                        }
                         ?><?php */?>
                </tr>
            <tr valign="top">
              <td align="right" class="rightmenu">Password:</td>
              <td><input name="password" type="password" class="body_text" 
id="password" /></td>
                <?php /*?><?php unset($FindPass);
                        if(isset($_POST['password']))
                        {
                            $_POST['password'] = 
trim($_POST['password']);
                            if(preg_match('/^[a-
zA-Z0-9^$.*+\[\]{,}]{1,32}$/u', $_POST['password']))
                                $$FindPass = 
$_POST['password'];
                        }
                         ?><?php */?>
                         <!--End of code added in the prevent SQL code injections-->
            </tr>

            <tr valign="top">
              <td>&nbsp;</td>
                  <td><input name="Submit" type="submit" class="body_text" 
value="Login" />

                   <?php 
                    function make_safe($variable) {
                        $variable = 
mysql_real_escape_string(trim($variable));
                        return $variable;
                    }

                    $username = make_safe($_POST['username']);
                    $password = make_safe($_POST['password']);
                    $check = mysql_query("SELECT Username, 
Password, UserLevel FROM Users WHERE Username = '".$username."' and Password = 
'".$password."'");

                    ?>

                  <br>
                  <br>
                  <a href="?section=forgot">Forgot your username or password?</a></td>
                </tr>
            <tr>
              <td>&nbsp;</td>
                  <td colspan="2">&nbsp;</td>
                </tr>
            </table></td>
          </tr>
        </table>
      </form>
    <? } else {  ?>
    <p class="body_text">You must <a href="?user_action=logout">logout</a> to continue 
to this page</p>
    <? } ?>
      </div></td>
    </tr>
</table>
</div>




我认为避免SQL注入的最好方法是在查询数据库时使用


此外,您还应该清理代码,使其更具可读性,使用MVC等设计模式将使其具有更好的结构。

我认为避免SQL注入的最佳方法是在查询数据库时使用


此外,您还应该清理代码,使其更具可读性,使用MVC等设计模式将使其具有更好的结构。

mysql\u*已被弃用,在较新版本中无法工作-您应该签出或取而代之

特别是()函数——这就是您现在应该如何处理用户输入(mysql\u real\u escape\u String()并不完美)


也就是说,在代码中,您永远不会连接到数据库-如果没有活动的DB连接,mysql\u real\u escape\u string()将无法工作

mysql\u*已被弃用,并且在较新版本中无法工作-您应该签出或取而代之

特别是()函数——这就是您现在应该如何处理用户输入(mysql\u real\u escape\u String()并不完美)


也就是说,您永远不会在代码中连接到数据库-如果没有活动的数据库连接,mysql\u real\u escape\u string()将无法工作

您的
make\u safe
函数定义在哪里?此外,为了清晰起见,从代码示例中删除所有HTML可能会有所帮助,因为它与数据清理工作无关。您的代码“不工作”的确切原因是什么?旁注:
$$FindPass=$\u POST['password']
可能应该是
$FindPass=$\u POST['password']。关于
make_safe
它就在那里,一直到最后。一般的想法是在查询中使用之前过滤用户名和密码。您可能正在使用make_safe()执行此操作,但我们看不到。更好的是,在用户输入时进行验证,这样您就可以提供正确格式的帮助。还有,签出PDO:
但我似乎无法正确理解这一点
你是认真的吗??我该拿那句话怎么办?请告诉我们更多关于这个问题的信息!!您是否收到任何错误?您的
make_safe
功能定义在哪里?此外,为了清晰起见,从代码示例中删除所有HTML可能会有所帮助,因为它与数据清理工作无关。您的代码“不工作”的确切原因是什么?旁注:
$$FindPass=$\u POST['password']
可能应该是
$FindPass=$\u POST['password']。关于
make_safe
它就在那里,一直到最后。一般的想法是在查询中使用之前过滤用户名和密码。您可能正在使用make_safe()执行此操作,但我们看不到。更好的是,在用户输入时进行验证,这样您就可以提供正确格式的帮助。还有,签出PDO:
但我似乎无法正确理解这一点
你是认真的吗??我该拿那句话怎么办?请告诉我们更多关于这个问题的信息!!您是否收到任何错误?
mysql\u*正在被清除,在较新版本中无法工作
哪个版本不起作用?@Deepak在较新版本中不会,但目前仍然有效working@rsz是的,我同意你!!从他的回答来看,它在新版本中似乎不起作用。。。应该说是未来的版本!!“
mysql\u real\u escape\u String()
不完美”到底是什么意思?哪些情况不包括在内?UTF8字符或如果您忘记了引号-mysql\u查询(“select*from user where id=“.mysql\u real\u escape\u string($\u GET[id]);仍然可以被注入()PDO/MySQLI为您在字符串周围加上引号-您不能忘记它们。
mysql_*正在被删除,在新版本中无法工作
哪个版本不起作用?@Deepak在新版本中不会,但目前仍然有效working@rsz是的,我同意你!!从他的回答来看,它在新版本中似乎不起作用。。。应该说是未来的版本!!“
mysql\u real\u escape\u String()
不完美”到底是什么意思?哪些情况不包括在内?UTF8字符或如果您忘记了引号-mysql\u查询(“select*from user where id=“.mysql\u real\u escape\u string($\u GET[id]);仍然可以被注入()PDO/MySQLI为您在字符串周围加上引号-您不能忘记它们。另请参阅PHP方式避免SQL注入的速成班。另请参阅PHP方式避免SQL注入的速成班。