> php教程 > php手册 > 본문

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

WBOY
풀어 주다: 2016-06-06 20:02:05
원래의
1161명이 탐색했습니다.

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 "<script>alert('使用非法字符!请文明上网,文明上网');location.href='' http://www.mps.gov.cn/n16/n1966474/“;</script>";
    
     exit();
   }else
   {
     return $get;
   }
}

}

调用方法

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

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

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

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



관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!