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; }