西数超哥博客
运维经验教程分享

php判断url中?后的值如果是数字.html或者为空,正常显示访问,否则就打开显示403

php判断url中?后的值如果是数字.html或者为空,正常显示访问,否则就打开显示403

if(!preg_match("/^[\d]+\.html$/",$_SERVER["QUERY_STRING"]) && !empty($_SERVER["QUERY_STRING"])){
echo "403";
exit;
} 

另外附加其他条件

if (!preg_match("/^[\d]+\.html$/",$_SERVER["QUERY_STRING"]) && !empty($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"]!="from=timeline&isappinstalled=0"&& $_SERVER["QUERY_STRING"]!="from=groupmessage&isappinstalled=0"&& $_SERVER["QUERY_STRING"]!="from=singlemessage&isappinstalled=0") {
echo "403";
exit;
}

补充:

http://localhost/aaa/?p=222 (附带查询)
结果:
$_SERVER[‘QUERY_STRING’] = “p=222”;
$_SERVER[‘REQUEST_URI’]  = “/aaa/?p=222”;
$_SERVER[‘SCRIPT_NAME’]  = “/aaa/index.php”;
$_SERVER[‘PHP_SELF’]     = “/aaa/index.php”;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<?php
echo "QUERY_STRING:";
echo $_SERVER['QUERY_STRING'];
echo "<br>";
echo "REQUEST_URI:";
echo $_SERVER['REQUEST_URI'];
echo "<br>";
echo "SCRIPT_NAME:";
echo $_SERVER['SCRIPT_NAME'];
echo "<br>";
echo "PHP_SELF:";
echo $_SERVER['PHP_SELF'];

?>

 

 

赞(0)
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥博客 » php判断url中?后的值如果是数字.html或者为空,正常显示访问,否则就打开显示403

评论 抢沙发

登录

找回密码

注册