Having your own host will generally design "anti-hotlinking", which actually includes anti-hotlinking for pictures, anti-hotlinking for downloads, etc., such as:
1. Use .htaccess to set anti-hotlinking
Copy code The code is as follows:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.) ?jb51.net/.*$ [NC]
RewriteRule .(gif|jpg)$ http://www.jb51.net/image.gif [R,L]
2.nginx settings Anti-hotlink
Copy code The code is as follows:
location ~* .(gif|jpg|png|swf|flv)$ {
valid_referers none blocked jb51.net;
if ($invalid_referer) {
rewrite ^/ http://jb51.net/234_s.gif;
#return 404;
}
}
But how to crack anti-hotlinking? Generally, anti-hotlinking is to determine whether the source is your own domain name. We can use PHP’s built-in file_get_contents method to request this image (of course other back-end languages also have similar methods) ), such as:
Copy code The code is as follows:
//getImg.php?url=Target image connection
php
header('Content-type: image/jpeg');
echo file_get_contents(isset($_GET["url"])?$_GET["url"]:'http://static.jb51 .net/images/v1/loading-16-16.gif');
?>
See example:
1, Directly load anti-hotlinking pictures: (Unauthorized pictures on this site are displayed blank)
2, read pictures through php:
http://www.bkjia.com/PHPjc/780483.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/780483.htmlTechArticleHaving your own host will generally design "anti-hotlinking", which actually includes anti-hotlinking for pictures, anti-hotlinking for downloads, etc. For example: 1. Use .htaccess to set up anti-hotlink copy code. The code is as follows: RewriteEngine on...
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