各位大神好,在下是小菜鸟一枚,在实践中发现,类似如下的语句:
<code>SELECT * FROM seller_item_classify where sid=$sid order by cweight asc ; </code>
其中$sid为前端传过来的数值,seller_item_classify为表明,sid为表中的一个字段名;
如果$sid传过来的值正好是'sid'的时候,SQL的这个where就失效了,造成了全表查询;
因为在生产环境中,$sid的值可能是数值,可能是char;我应该在php里做对前端输入值的过滤?
请问各位是如何看这个问题?
各位大神好,在下是小菜鸟一枚,在实践中发现,类似如下的语句:
<code>SELECT * FROM seller_item_classify where sid=$sid order by cweight asc ; </code>
其中$sid为前端传过来的数值,seller_item_classify为表明,sid为表中的一个字段名;
如果$sid传过来的值正好是'sid'的时候,SQL的这个where就失效了,造成了全表查询;
因为在生产环境中,$sid的值可能是数值,可能是char;我应该在php里做对前端输入值的过滤?
请问各位是如何看这个问题?
<code>"SELECT * FROM seller_item_classify where sid='$sid' order by cweight asc ;"</code>
对于前端输入值,后端必须过滤,建议使用sql预处理。
SQL的条件值都加''
<code>sid = '$sid'</code>
as 别名 好使吗?
加上单引号就解决了
'SELECT * FROM seller_item_classify where sid='.$sid.' order by cweight asc ;'
用pdo预处理吧
<code><?php
$sid = issset($_REQUEST['sid']) ? htmlspecialchars(trim($_REQUEST['sid'])) : '';
if (!$sid or $sid=='sid') {
// 非法请求 这里可以抛出一些异常
}</code>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号