欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

浅谈php正则过滤sql注入,以及跨站脚本攻击 新人学习

程序员文章站 2022-06-06 14:11:33
...

php 正则方法 ?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * Description of checksql * * @autho

php 正则方法

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of checksql
*

* @author xt

*/
class checkURL{
function inject_check($get) {
$checkurl=eregi('select|insert|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile|or|and|-||&|%|limit|where|oR|aNd', $get);//要匹配的字符
if($checkurl)
{
echo "";

exit();
}else
{
return $get;
}
}

}

调用方法

require_once 'url/checksql.php'; //根据自己的路径

$check=new checkURL(); //创建对象
$id=$check->inject_check($_GET['id']); //将url传入的参数 传入调用的正则方法

参数$id 匹配过后可以去传入自定义方法使用

以上方法 如有问题或是其他的更好的意见及建议 欢迎大家一起交流