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'];
?>