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操作路由器实现方法示例

本文实例讲述了PHP操作路由器实现方法。分享给大家供大家参考,具体如下: 用PHP操作路由器 我们经常会碰到需要自动换IP的需求,比方模拟点击投票,数据采集被封IP,Alexa作弊等等,...

PHP 获取远程文件大小的3种解决方法

1、使用file_get_contents()复制代码 代码如下:<?php$file = file_get_contents($url);echo strlen($file);?...

php foreach循环中使用引用的问题

看代码,再做解释复制代码 代码如下:<?php $array=array('a','b','c','d'); foreach($array as $key=>$val){ &...

PHP5.3连接Oracle客户端及PDO_OCI模块的安装方法

本文实例讲述了PHP5.3连接Oracle客户端及PDO_OCI模块的安装方法。分享给大家供大家参考,具体如下: php连接oracle数据库虽然不是最佳拍档,但组内开发确实有这样需求。...

php常量详细解析

一、常量 常量是一个简单值的标识符(名字)。如同其名称所暗示的,在脚本执行期间该值不能改变(除了所谓的魔术常量,它们其实不是常量)。常量默认为大小写敏感。按照惯例常量标识符总是大写的。...