入口出判断请求来源

仅本站访问或者没有跳转的可以访问:

1 if (isset($_SERVER["HTTP_REFERER"])) {

2     $referer = $_SERVER["HTTP_REFERER"];

3     if (strpos($referer, 'http://***.***.com.cn') !== 0) {

4         header('HTTP/1.1 404 Not Found');

5         header("status: 404 Not Found");

6         echo 'ERROR 404';

7         exit();

8     }

9 }

 禁止?/和/?的访问形式:

$url = $_SERVER['REQUEST_URI'];

$regex1 = '/.*\?\/.*/';

$regex2 = '/.*\/\?.*/';

if (preg_match($regex1, $url) || preg_match($regex2, $url)) {

    header('HTTP/1.1 404 Not Found');

    header("status: 404 Not Found");

    echo 'ERROR 404';

    exit;

}

 

你可能感兴趣的:(判断)