朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

PHP 过滤 post,get传入内容,防止字符串注入

介绍

可以简单拦截POST,GET传入的危险字符,有效防止字符串注入

拦截页面也是仿的宝塔的,截图演示:

PHP 过滤 post,get传入内容,防止字符串注入插图

代码

<?php
function safe_html(){
	echo <<<HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>网站防火墙</title>
<style>
*{margin:0;padding:0;color:#444}
body{font-size:14px;font-family:"宋体"}
.main{width:600px;margin:10% auto;}
.title{background: #20a53a;color: #fff;font-size: 16px;height: 40px;line-height: 40px;padding-left: 20px;}
.content{background-color:#f3f7f9; height:280px;border:1px dashed #c6d9b6;padding:20px}
.t1{border-bottom: 1px dashed #c6d9b6;color: #ff4000;font-weight: bold; margin: 0 0 20px; padding-bottom: 18px;}
.t2{margin-bottom:8px; font-weight:bold}
ol{margin:0 0 20px 22px;padding:0;}
ol li{line-height:30px}
</style>
</head>

<body>
	<div class="main">
		<div class="title">网站防火墙</div>
		<div class="content">
			<p class="t1">您的请求带有不合法参数,已被网站管理员设置拦截!</p>
			<p class="t2">可能原因:</p>
			<ol>
				<li>您提交的内容包含危险的攻击请求</li>
			</ol>
			<p class="t2">如何解决:</p>
			<ol>
				<li>检查提交内容;</li>
				<li>如网站托管,请联系空间提供商;</li>
				<li>普通网站访客,请联系网站管理员;</li>
				<li>这是误报,请提交工单 <a href="https://www.zhuchunshu.com/requests" target="_brank">https://www.zhuchunshu.com/requests</a></li>
			</ol>
		</div>
	</div>
</body>
</html>


HTML;
}
function safes()
	{
	    foreach($_REQUEST as $sql_str){
		    $check= preg_match('/and|or|where|limit|group by|select|insert|eval|system|exec|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile/i',$sql_str);
		    if ($check) {
		    	safe_html();
		        die;
		    }
		}
	}
safes();
?>

使用方法

新建一个PHP文件,把上面的代码贴进去并保存,然后引入这个文件即可

赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » PHP 过滤 post,get传入内容,防止字符串注入

评论 183

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #195

    Hurda bakır alan istanbul hurdacı firması olarak her türlü madeni değerinde alıyoruz hurdacı istanbul hurdaci https://www.hurdacisitesi.com.tr

  2. #194

    İstanbul hurdacı firması olarak tüm hurdalarınızı adresinizden alıyoruz.

    hurdaci2周前 (03-14)回复