As is known to all, a website if the picture traffic is occupied by the network bandwidth, so that the theft of pictures to prevent the link appears to be the most important. Here, briefly explain how Baidu to prevent the hotlinking of the principle of the picture, and then introduce how to steal pictures through PHP, is so-called, however persuasive outsmart, defensive and offensive always mutually promote development.
First, a brief introduction of the next hotlinking, according to the introduction of Baidu Encyclopedia " Hotlinking refers to the service provider itself does not provide the content of the service, through technical means to bypass other beneficial end user interface (such as advertising), directly on their own website to the end user to provide other service provider service content, Cheat End-user browsing and Ctr. Beneficiaries do not provide resources or provide very little resources, and real service providers do not get any benefits. ". So, here is the picture hotlinking is on its own server reference Baidu image results, and do not put the picture on their own server, thus reducing the bandwidth of the server.
For example: Give the URL of a Baidu image:
http://c.hiphotos.baidu.com/image/w%3D210/sign=ed30880babec8a13141a50e1c7029157/ D52a2834349b033be1a9503e17ce36d3d539bd35.jpg
If accessed directly through a browser, we will get real pictures, such as:
But if we're on our own server,
To get the contents of it.
Then we will get the following picture:
Here, because we requested the image of the HTTP request in the header of the Referer: This field, he marked that we are not Baidu's own server, so the request is not handled normally, here we can use the Curl extension in PHP to forge the HTTP request to get the correct picture. The code is as follows:
<?php$url = ' http://c.hiphotos.baidu.com/image/w%3D210/sign=ed30880babec8a13141a50e1c7029157/ D52a2834349b033be1a9503e17ce36d3d539bd35.jpg ';//$_get["url"]; $dir = PathInfo ($url); $host = $dir [' dirname ']; $refer = $host. ' /'; $ch = Curl_init ($url); curl_setopt ($ch, Curlopt_referer, $refer); curl_setopt ($ch, Curlopt_returntransfer, true);// Activation can modify the pagecurl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_binarytransfer, 1); $data = curl_exec ($ch); Curl_close ($ch); Header ("Content-type:image/jpeg");p rint ($data);
After this processing, we can steal the image of Baidu.