Home > Article > Backend Development > Function analysis on php cracking anti-hotlink pictures
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['url']; $ext=pathinfo($url,PATHINFO_EXTENSION); if($ext!='jpg' && $ext!='gif'){ // 只支持jpg和gif readfile('/upload/20081209130557536.gif'); exit; } $file=md5($url).'.'.$ext; if(file_exists($file)){ readfile($file); exit; }else{ $data=file_get_contents($url); if(!$data){ // 读取失败 readfile('/upload/20081209130557536.gif'); exit; } $handle=fopen($file,'wb'); 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!