Home > Backend Development > PHP Problem > php non-specified URL cannot be accessed

php non-specified URL cannot be accessed

angryTom
Release: 2023-02-28 11:28:01
Original
2125 people have browsed it

php non-specified URL cannot be accessed

php non-specified URL cannot be accessed

1. First define an array $allow_url to store the domain name whitelist. That is, the address that can access this website;

2. Then get $_SERVER['HTTP_REFERER'];

3. Then determine whether the visitor is in the whitelist, and then Run access, otherwise not allowed.

$allow_url = [
    0 => 'eva.com',
    1 => 'localhost',
];

$refer = $_SERVER['HTTP_REFERER'];

$pattern = '/^(http|https):\/\/?([^\/]+)/i';
preg_match($pattern, $refer, $match);

$demain_name = $match[2];
if (in_array($demain_name, $allow_url)) {
    echo 'ok';
}else{
    die('不允许的域名');
}
Copy after login

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of php non-specified URL cannot be accessed. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template