Home >Backend Development >PHP Tutorial >php image file download file anti-hotlink setting method_PHP tutorial
The simplest way to prevent hotlinking in PHP is to use PHP's $_SERVER['HTTP_REFERER'] function to operate. However, this method is unreliable. We will eventually need to use apache and iis to operate. Below I Shared introduction, friends in need can refer to it.
php anti hotlink
The code is as follows
|
Copy code
|
||||
代码如下 | 复制代码 | ||||
session_start(); ?> |
session_register(‘check’);
$_SESSION[‘check’]=true;?>
Check the session variable to determine whether to visit the homepage. And check whether his source web page reference (HTTP_REFERER) comes from a web page on the local website.
Here’s how:
The code is as follows
|
Copy code
|
||||||||||||||||||||
$refs = parse_url($_SERVER['HTTP_REFERER']); //Decompose reference web page information //Check whether the homepage session and source host are the same if(!($_SESSION['check']) || $refs['host'] != $_SERVER['HTTP_HOST']) exit;
Statement: 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 Previous article:PHPCMS 2008 latest vulnerability demo test detailed explanation_PHP tutorialNext article:PHPCMS 2008 latest vulnerability demo test detailed explanation_PHP tutorial Related articlesSee more |