php快速查找数据库中恶意代码的方法
发布于 2015-04-04 14:54:43 | 121 次阅读 | 评论: 0 | 来源: 网友投递
PHP开源脚本语言PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。
本文实例讲述了php快速查找数据库中恶意代码的方法。分享给大家供大家参考。具体如下:
数据库被输入恶意代码,为了保证你的数据库的安全,你必须得小心去清理。有了下面一个超级方便的功能,即可快速清除数据库恶意代码。
function cleanInput($input) {
$search = array(
'@]*?>.*?@si', // Strip out javascript
'@]*?>@si', // Strip out HTML tags
'@
]*?>.*?
@siU', // Strip style tags properly
'@@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
return $output;
}
function sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
$input = cleanInput($input);
$output = mysql_real_escape_string($input);
}
return $output;
}
// Usage:
$bad_string = "Hi! It's a good day!";
$good_string = sanitize($bad_string);
// $good_string returns "Hi! It's a good day!"
// Also use for getting POST/GET variables
$_POST = sanitize($_POST);
$_GET = sanitize($_GET);
相关阅读:
php快速查找数据库中恶意代码的方法
php在文件指定行中写入代码的方法
php去除数组中重复数据的方法
PHP间隔一段时间执行代码的方法
php连接oracle数据库及查询数据的方法
php删除文本文件中重复行的方法
php删除数组中重复元素的方法
PHP快速生成各种信息提示框的方法
PHP获取数组中单列值的方法
通过php快速统计某个数据库中每张表的数据量
php获取mysql数据库中的所有表名的代码
PHP查询数据库中满足条件的记录条数(两种实现方法)