Home > Backend Development > PHP Tutorial > php curl 作采集时的一些参数设置

php curl 作采集时的一些参数设置

WBOY
Release: 2016-06-23 13:39:27
Original
929 people have browsed it

    public function geturl($url){                $ip = "{rand(1, 255)}.{rand(1, 255)}.{rand(1, 255)}.{rand(1, 255)}";                // 初始化一个 cURL 对象        $curl = curl_init();        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/$ip Safari/536.11");        curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-FORWARDED-FOR:$ip", 'CLIENT-IP:'.$ip.''));        //curl_setopt($curl, CURLOPT_REFERER, "127.0.0.1");        // 设置你需要抓取的URL        curl_setopt($curl, CURLOPT_URL, $url);        // 设置header        curl_setopt($curl, CURLOPT_HEADER, 1);        // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);        // 运行cURL,请求网页        $data = curl_exec($curl);        // 关闭URL请求        curl_close($curl);        return $data;    }
Copy after login

以上设置可以防止普通的防采集功能,效果挺明显的
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template