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程序设计有所帮助。

相关文章

coreseek 搜索英文的问题详解

问题描述: 被搜索名字为:andy 这时搜索andy正常,但是搜索a就搜不到。 解决办法,在索引配置文件中的index中添加min_infix_len = 1最后还要重新索引一下/usr...

Windows平台PHP+IECapt实现网页批量截图并创建缩略图功能详解

Windows平台PHP+IECapt实现网页批量截图并创建缩略图功能详解

本文实例讲述了Windows平台PHP+IECapt实现网页批量截图并创建缩略图功能。分享给大家供大家参考,具体如下: 最近在开发一个本地互联网应用的项目,为了增加用户体验,需要在搜索结...

PHP/HTML混写的四种方式总结

PHP/HTML混写的四种方式总结

PHP作为一款后端语言,为了输出给浏览器让浏览器呈现出来,无可避免的要输出HTML代码,下文介绍下我用过的三种PHP/HTML混编方法 1、单/双引号包围法 这是最初级的方法了,用法就像...

PHP中spl_autoload_register函数的用法总结

spl_autoload_register(PHP 5 >= 5.1.2)spl_autoload_register — 注册__autoload()函数 说明bool spl_a...

自动分页的不完整解决方案

测试代码 <form id="form1" name="form1" method="post" action="">  &...