Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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 数据库查询和报价_Php_Security_Url_Quotes - Fatal编程技术网

Php 数据库查询和报价

Php 数据库查询和报价,php,security,url,quotes,Php,Security,Url,Quotes,如果我使用http://site.com/index.php?page=45一切正常(需要加载页面) 但是当我通过http://site.com/index.php?page=45“或http://site.com/index.php?page=45“(引号添加在数字后)页面打印错误: Unhandled Exception (Debug) You have an error in your SQL syntax; check the manual that corresponds to you

如果我使用
http://site.com/index.php?page=45
一切正常(需要加载页面)

但是当我通过
http://site.com/index.php?page=45“
http://site.com/index.php?page=45“
(引号添加在数字后)页面打印错误:

Unhandled Exception (Debug)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'
 ORDER BY datePub DESC
 LIMIT 10' at line 9
SELECT *, date_format(date, '%d') AS day, date_format(date, '%m') AS month, date_format(date, '%Y') AS year FRO...
// and paths to my scripts
对哈克来说,这就像披萨和啤酒

如何过滤不需要的符号(如引号),以便页面不会显示我的db查询(可能是我自己的错误文本)?

我已经关闭了错误报告,但它不是一个解决方案(不能在任何地方使用它)


键入
页面
变量:

可能的解决办法1: 测试用例:

$str = '45"';
echo (int) $str;
45
结果:

$str = '45"';
echo (int) $str;
45
可能的解决办法2: 或者您可以使用
is\u numeric
ctype\u digit
功能拒绝此类无效值:

if (!ctype_digit($_GET['page'])){
   die('Invalid page value !!');
}
else{
 // continue with the query...
}
可能的解决办法3: 您可以使用此正则表达式删除不需要的字符:

$page = preg_replace("/[^0-9]+/", "", $_GET['page']);
更新:
对于文本,您应该使用
mysql\u real\u escape\u string
函数。

使用(int)$\u GET['page']。如果这样做不起作用,您正在抓取url,这意味着您需要使用正则表达式。我不明白您为什么要抓取url,所以您应该没事。

这是什么意思?显示您的代码,如何使用它…强制转换为int将其计算为int,删除数字后的任何内容。preg_“替换”将删除除数字以外的任何内容。如果这两个选项都没有帮助,那么问题就更大了。(int)type将变量转换为整数。lookup type casting>在数字之后,这很好,但是数字的中间或开头呢?可以在那里使用。好的,然后选择preg_replace选项。但是在那个时候,显然有人试图攻击你,所以你想尝试将其解析到某个页面吗?显然他们没有试图达到,踢他们在第1页,或做一些关于他们试图黑客你?如果引用是在中间的号码,或在开始?报价也可以使用在一些文本,如变量,如类型=新闻'。如何以这种方式过滤?@努力:在这种情况下,你应该考虑其他方法,比如我有Surn.Tror的数字,文本怎么样?:@WorkingHard:对于文本,使用
mysql\u real\u escape\u string
函数。
$page = preg_replace("/[^0-9]+/", "", $_GET['page']);