Function analysis on php cracking anti-hotlink pictures

不言
Release: 2023-04-01 16:58:01
Original
2108 people have browsed it

This article mainly introduces the function analysis of PHP cracking anti-hotlink images. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

Only supports jpg and gif. Everyone. It can be modified to support multiple image formats

<?php 
$url=$_GET[&#39;url&#39;]; 
$ext=pathinfo($url,PATHINFO_EXTENSION); 
if($ext!=&#39;jpg&#39; && $ext!=&#39;gif&#39;){ // 只支持jpg和gif 
readfile(&#39;/upload/20081209130557536.gif&#39;); 
exit; 
} 
$file=md5($url).&#39;.&#39;.$ext; 
if(file_exists($file)){ 
readfile($file); 
exit; 
}else{ 
$data=file_get_contents($url); 
if(!$data){ // 读取失败 
readfile(&#39;/upload/20081209130557536.gif&#39;); 
exit; 
} 
$handle=fopen($file,&#39;wb&#39;); 
fwrite($handle,$data); 
fclose($handle); 
echo $data; 
} 
?>
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website !

Related recommendations:

About how to use exec, system and other functions to call system commands in PHP

How to use PHP Forged referer breaks through the network disk and prohibits external connections

The above is the detailed content of Function analysis on php cracking anti-hotlink pictures. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!