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下通过file_get_contents的代理使用方法

PHP使用file_get_contents的代理方法获取远程网页的代码。 复制代码 代码如下: <?php $url = "//www.jb51.net/"; $ctx = st...

php session和cookie使用说明

1. PHP的COOKIE cookie 是一种在远程浏览器端储存数据并以此来跟踪和识别用户的机制。PHP在http协议的头信息里发送cookie, 因此setcookie() 函数必须...

php强制下载类型的实现代码

复制代码 代码如下: function downloadFile($file){ /*Coded by Alessio Delmonti*/       &...

php获得用户ip地址的比较不错的方法

REMOTE_ADDR只能获取访问者本地连接中设置的IP,如某大学校园网中自己设置的10.X.XXX.XXX系列IP,而这个函数获取的是局域网网关出口的IP地址,如果访问者使用代理服务器...

php文件下载处理方法分析

本文实例讲述了php文件下载的处理方法。分享给大家供大家参考。具体分析如下: php能够处理多种条件的文件下载,先来看下面示例: <?php header("Conte...