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;
source:php.cn
Previous article:PHPCMS 2008 latest vulnerability demo test detailed explanation_PHP tutorial
Next article:Detailed explanation of php mysql_real_escape_string anti-sql injection_PHP tutorial
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
Latest Articles by Author
Latest Issues
When adding sublime3 to compile system php, use the PHP toolbox, cmd php -v is useless
From 1970-01-01 08:00:00
0
0
0
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|