[php] 2024-04-19 圈点532
摘要:php使用curl进行IP代理访问的操作如下所示。如果访问内容,说明就是代理OK,如果返回false,说明代理无效。
php使用curl进行IP代理访问的操作如下所示:
header("Content-type: text/html; charset=utf-8");
//测试验证代理
$requestUrl = 'www.xoxxoo.com';
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
curl_setopt($ch, CURLOPT_PROXY, "180.164.39.242"); //代理服务器地址
curl_setopt($ch, CURLOPT_PROXYPORT, 12635); //代理服务器端口
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, ":"); //http代理认证帐号,username:password的格式
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式
$file_contents = curl_exec($ch);
curl_close($ch);
var_dump($file_contents);
exit();
php使用curl进行IP代理访问的操作如下所示。如果访问内容,说明就是代理OK,如果返回false,说明代理无效。