For websites that have restricted IP and sources, it is not possible to use normal acquisition methods. This article will introduce a method that uses the PHP Curl class to achieve analog IP and source, and to capture websites that limit IP and source.
1. Set page limit IP and source access
server.php
<?php $client _ip = GetIP (); $referer = Getreferer (); $allow _ip = ' 192.168.1.100 '; $allow _referer = ' http://www.uxuew.cn '; if ($client _ip== $allow _ip && strpos ($referer, $allow _referer) ===0) { echo ' Allow access ';} else{ echo ' Deny Access ';} Get visitor ipfunction GetIP () { if (!empty ($_server[' http_client_ip ')) {$cip = $_server[' http_client_ip ']; } ElseIf (!empty ($_server[' http_x_forwarded_for ')) {$cip = $_server[' http_x_forwarded_for ']; } ElseIf (!empty ($_server[' remote_addr ')) {$cip = $_server[' remote_addr ']; } else{$cip = '; } return $CIP;} Get visitor Source Function Getreferer () { if (isset ($_server[' http_referer ')) {return $_server[' http_referer ']; } Return ';} ?>
2. Normal access Using Curl
<?phpfunction Docurl ($url, $data =array (), $header =array (), $timeout =30) { $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_httpheader, $header); curl_setopt ($ch, Curlopt_post, true); curl_setopt ($ch, Curlopt_postfields, Http_build_query ($data)); curl_setopt ($ch, Curlopt_returntransfer, true); curl_setopt ($ch, Curlopt_timeout, $timeout); $response = curl_exec ($ch); if ($error =curl_error ($ch)) {die ($error); } Curl_close ($ch); return $response; }//Call the ' http://www.uxuew.cn/server.php ', $response = Docurl ($url); Echo $response;? >
3. Use Curl to simulate IP and source access
Analog sources
curl_setopt ($ch, Curlopt_referer, ' source ');
Analog IP
curl_setopt ($ch, Curlopt_httpheader, Array (' CLIENT-IP: Analog ip ', ' x-forwarded-for: Analog IP '));
The complete code is as follows:
<?phpfunction Docurl ($url, $data =array (), $header =array (), $referer = ", $timeout =30) { $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_httpheader, $header); curl_setopt ($ch, Curlopt_post, true); curl_setopt ($ch, Curlopt_postfields, Http_build_query ($data)); curl_setopt ($ch, Curlopt_returntransfer, true); curl_setopt ($ch, Curlopt_timeout, $timeout); Analogue source curl_setopt ($ch, Curlopt_referer, $referer); $response = curl_exec ($ch); if ($error =curl_error ($ch)) {die ($error); } Curl_close ($ch); return $response; }//Call the ' http://www.example.com/server.php ', $data = Array (); Set Ip$header = Array ( ' client-ip:192.168.1.100 ', ' x-forwarded-for:192.168.1.100 ');//Set Source $referer = ' Http://www.uxuew.cn/'; $response = Docurl ($url, $data, $header, $referer, 5); Echo $response;? >