php快速查找数据库中恶意代码的方法

yipeiwu_com6年前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-fpm.conf配置文件中文说明详解及重要参数说明

php-fpm.conf配置文件中文说明详解及重要参数说明

php-fpm工作流程 php-fpm全名是PHP FastCGI进程管理器 php-fpm启动后会先读php.ini,然后再读相应的conf配置文件,conf配置可以覆盖php.ini...

PHP var_dump遍历对象属性的函数与应用代码

本文章下面我们要为你提供二种关于遍历对象属性方法,并且举例说明遍历对象属性在php中的应用。可以看出私有变量与静态变量时获取不到的,只有定义为公共变量才可以读出来。 遍历对象属性第一种方...

PHP 缓存实现代码及详细注释

复制代码 代码如下:class CacheException extends Exception {} /** * 缓存抽象类 */ abstract class Cache_Abstr...

PHP中常用的魔术方法

我们在PHP中经常用到魔术方法,像构造方法,析构方法等等魔术变量,下面总结一下一些常用的魔术变量: __construct(),__destruct(),__clone(),__auto...

apache+codeigniter 通过.htcaccess做动态二级域名解析

复制代码 代码如下: AuthName "yousite Website Coming Soon..." //如果你想给你的网站加个权限访问 AuthType Basic AuthUse...