PHP application-Baidu image of the anti-theft chain

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.