Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/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 magento中的反sql注入_Php_Magento_Sql Injection - Fatal编程技术网

Php magento中的反sql注入

Php magento中的反sql注入,php,magento,sql-injection,Php,Magento,Sql Injection,我搜索了反sql注入代码。下面的代码是我采用的。 我想再次确认以下php代码可以阻止sql注入 $sql_select = " SELECT * FROM main_tbl WHERE ( (((main_tbl.from_id = :sender_id) AND (main_tbl.to_id = :to_id)) OR ((main_tbl.to_id = :sender_id) AND (main_tbl.from_id = :to_id))) AND (m

我搜索了反sql注入代码。下面的代码是我采用的。 我想再次确认以下php代码可以阻止sql注入

$sql_select = "
SELECT
    *
FROM main_tbl
WHERE 
(
  (((main_tbl.from_id = :sender_id) AND (main_tbl.to_id = :to_id)) 
    OR ((main_tbl.to_id = :sender_id) AND (main_tbl.from_id = :to_id)))
  AND
  (main_tbl.last_date > :lasttime)
);
";

$binds = array(
    'sender_id' => $sender_id, 
    'to_id' => $to_id,
    'sender_id' => $sender_id,
    'to_id' => $to_id,
    'lasttime' => $lasttime
);
$resource = Mage::getModel('core/resource');
$read = $resource->getConnection('core_read');
$results = $read->fetchAll($sql_select, $binds);

是的,此代码没有显示任何漏洞,应该是安全的。一个好的经验法则是始终验证用户输入


然而,您的代码有点缺陷,但从您对问题的评论来看,我认为您已经知道了。

它不会起作用,因为您的数组中只有3个项目,但有5个绑定占位符。(假定PDO仿真模式已关闭)这可能有问题,因为我提取了部分源代码。那么Bind呢,Bind肯定是反sql注入代码吗?我不知道你的意思。。一般来说,如果您不知道后台发生了什么(没有阅读文档,然后是源代码),经验法则是如果您需要在SQL语句中使用
:param
,并将数组传递到API,那么您最可能的“反SQL注入”是安全的。。