Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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 空检查和isset检查中的sql注入漏洞_Php_Sql - Fatal编程技术网

Php 空检查和isset检查中的sql注入漏洞

Php 空检查和isset检查中的sql注入漏洞,php,sql,Php,Sql,我目前正在制作我的站点注入证明,我想知道我正在进行的验证,我的代码如下: if(!empty($_POST['city']) && !empty($_POST['street'])){ $city = htmlentities(mysql_real_escape_string($_POST['city'])); $street = htmlentities(mysql_real_escape_string($_POST['street'])); } $userna

我目前正在制作我的站点注入证明,我想知道我正在进行的验证,我的代码如下:

if(!empty($_POST['city']) && !empty($_POST['street'])){
  $city = htmlentities(mysql_real_escape_string($_POST['city']));
  $street = htmlentities(mysql_real_escape_string($_POST['street']));   
}
$username = $_GET["username"];

mysql_query("SELECT 1 FROM `users` WHERE `username` = '" . $username . "'");
我的问题是空支票本身不是一个漏洞吗? 我的意思是我一定要逃出绳子!还有空验证吗?或者这样做是安全的?
谢谢。

对于SQL注入,您只需要在查询数据库时担心,因此isset是安全的

htmlentities应该不需要使用它来保护XSS

mysql\u real\u escape\u字符串可以防止SQL注入,但不应该使用,因为mysql\u prefix/DB处理程序已经过时,不推荐使用,根本不应该使用。
最安全的方法是使用或,并使用准备好的语句。

对于SQL注入,您只需要在查询数据库时担心,因此isset是安全的

htmlentities应该不需要使用它来保护XSS

mysql\u real\u escape\u字符串可以防止SQL注入,但不应该使用,因为mysql\u prefix/DB处理程序已经过时,不推荐使用,根本不应该使用。
最安全的方法是使用或,并使用准备好的语句。

SQL注入漏洞的工作原理如下:

if(!empty($_POST['city']) && !empty($_POST['street'])){
  $city = htmlentities(mysql_real_escape_string($_POST['city']));
  $street = htmlentities(mysql_real_escape_string($_POST['street']));   
}
$username = $_GET["username"];

mysql_query("SELECT 1 FROM `users` WHERE `username` = '" . $username . "'");
现在,如果$\u GET[username]的值类似于foo'或1=1-

查询:

SELECT 1 FROM `users` WHERE `username` = 'foo' OR 1=1
--'
将运行选择所有用户的

如果您转义输入,您将得到预期的查询:

SELECT 1 FROM `users` WHERE `username` = 'foo\' OR 1=1--'
PHP函数本身不易受攻击


也许这是一个很好的类比:当有人说说出你的名字时,他们希望你说我是约翰,而不是你的名字

if(!empty($_POST['city']) && !empty($_POST['street'])){
  $city = htmlentities(mysql_real_escape_string($_POST['city']));
  $street = htmlentities(mysql_real_escape_string($_POST['street']));   
}
$username = $_GET["username"];

mysql_query("SELECT 1 FROM `users` WHERE `username` = '" . $username . "'");
现在,如果$\u GET[username]的值类似于foo'或1=1-

查询:

SELECT 1 FROM `users` WHERE `username` = 'foo' OR 1=1
--'
将运行选择所有用户的

如果您转义输入,您将得到预期的查询:

SELECT 1 FROM `users` WHERE `username` = 'foo\' OR 1=1--'
PHP函数本身不易受攻击


也许这是一个很好的类比:当有人说说出你的名字时,他们想让你说我是约翰,而不是你的名字

这是没有用的;不,空的不是脆弱的,不需要逃避,没关系。了解注入漏洞实际上是什么:。还有,为什么要逃避太多.htmlentities是多余的,如果您一直担心sql注入,请转到下面的URL。它已经被问到了,并且得到了很高的回答,这是没有用的;不,空的不是脆弱的,不需要逃避,没关系。了解注入漏洞实际上是什么:。还有,为什么要逃避太多.htmlentities是多余的,如果您一直担心sql注入,请转到下面的URL。有人问过它,并得到了高比率的答案。输入错误-在您的示例中,它将删除表而不是数据库:这是一个坏例子,因为mysql\u查询默认情况下不会在一个字符串中执行多个查询。输入错误-在您的示例中,它将删除表而不是数据库:这是一个坏例子,因为mysql\u查询不会执行多个查询默认情况下,查询为一个字符串。