Php method for preventing image leeching-PHP source code

Source: Internet
Author: User
Ec (2); http_referer, the simplest picture piracy is to use this super global variable in the php tutorial for an instance, but this function can be easily cracked, the reason is that we can write a class to send related information from the browser. The Code is as follows. Functiongetremotefile ($ url, $ refer) {$ optionarray (http & gt; array (header & gt; script ec (2); script

Http_referer, the simplest image piracy is to use this super global variable in the php tutorial for an instance, but this function can be easily cracked, the reason is that we can write a class to send related information from the browser. The Code is as follows.

Function getremotefile ($ url, $ refer = ''){
$ Option = array (
'Http' => array (
'Header' => "referer: $ refer ")
);
$ Context = stream_context_create ($ option );
Return file_get_contents ($ url, false, $ context );
}

Stream_context_create creates and returns a text data stream and applies various options. It can be used in special procedures such as timeout settings, proxy server, request method, and header information settings for fopen (), file_get_contents () and other processes.

Function prototype: resource stream_context_create ([array $ options [, array $ params])


For more details, see: http://www.111cn.net/phper/php-function/36535.htm

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.