保障数据库查询与文件操作的安全
1. SQL注入与db_query()的安全使用
SQL注入是一种常见的攻击网站的方式。下面我们来看一个没有考虑安全问题的模块示例,该模块的目的是简单列出特定类型节点的标题:
/*
* Implementation of hook_menu().
*/
function insecure_menu() {
$items['insecure'] = array(
'title' => 'Insecure Module',
'description' => 'Example of how not to do things.',
'page callback' => 'insecure_code',
'access arguments' => array('access content'),
);
return $items;
}
/*
* Menu callback, called when user goes to http://example.com/?q=insecure
*/
function insecure_code($type = 'story') {
// SQL statement where variable is embedded directly into the statement.
$sql = "SELECT title FROM {node} WHERE type = '$type'"; // Never do this!
$result = db_
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



