If you want to break through anti-Leech measures, you need to consider using HTTP_REFERER. Many websites use referer to determine whether to steal links. If you want to take measures to break through the anti-Leech protection, you need to consider using HTTP_REFERER. The corresponding variable in the PHP script is $ _ SERVER ['http _ referer'], which stores the value of HTTP_REFERER.
Because direct access to the target URL resource has been blocked by the above anti-Leech measures, we need a gateway-like device to obtain it. To put it bluntly, you can compile a PHP script that has packaged the HTTP header.
The following is a simple function implementation:
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 );
}
This is a simple function. its function is to forge a Referer (using the stream_context_create function) and then obtain the data of the other party (using file_get_contents, you need to enable allow_url_fopen ).
If you want to be "complex", you can use the sockets extension, which is not covered here.
In addition, a regular function is provided to obtain the host name.
The code is as follows:
Function getHost ($ url ){
$ Result = preg_match ('/^ http: \/([\ d | \ w | \.] +) \ //', $ url, $ matches );
If (sizeof ($ matches)> = 2 ){
Return $ matches [1];
} Else {
Return null;
}
}
Further extensions can be encapsulated into scripts, such as calling
Http: // 127.0.0.1/proxy. php? Url = http:// I .am/imgcan get some of the anti-Leech links (and then use Javascript to replace all the image links ).