Some parameter settings for PHP curl for collection

Source: Internet
Author: User

    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

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.