Public Function Geturl ($url) { $ip = "{rand (1, 255)}.{ RAND (1, 255)}. {rand (1, 255)}. {rand (1, 255)} "; Initializes a CURL object $curl = Curl_init (); curl_setopt ($curl, Curlopt_useragent, "mozilla/5.0 (Windows NT 6.1) applewebkit/536.11 (khtml, like Gecko) chrome/$ip SAF ari/536.11 "); curl_setopt ($curl, Curlopt_httpheader, Array ("X-forwarded-for: $ip", ' Client-ip: '. $ip. ')); curl_setopt ($curl, Curlopt_referer, "127.0.0.1"); Set the URL you need to crawl curl_setopt ($curl, Curlopt_url, $url); Set HEADER curl_setopt ($curl, Curlopt_header, 1); Sets the curl parameter, which requires the result to be saved to a string or output to the screen. curl_setopt ($curl, Curlopt_returntransfer, 1); Run Curl, request page $data = curl_exec ($curl); Close URL request curl_close ($curl); return $data; }
The above settings can prevent the normal anti-collection function, the effect is quite obvious
Some parameter settings for PHP curl for collection