Home  >  Article  >  Backend Development  >  Function analysis on php cracking anti-hotlink pictures

Function analysis on php cracking anti-hotlink pictures

不言
不言Original
2018-06-21 15:13:582134browse

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; 
} 
?>

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!

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