php uses proxy to access website method

伊谢尔伦
Release: 2016-11-26 16:35:51
Original
4498 people have browsed it

<?php
 
$requestUrl = &#39;php.cn&#39;;
 
$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, "112.23.451.72"); //代理服务器地址
 
curl_setopt($ch, CURLOPT_PROXYPORT, 80); //代理服务器端口
 
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, ":"); //http代理认证帐号,名称:pwd的格式
 
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //使用http代理模式
 
$file_contents = curl_exec($ch);
 
curl_close($ch);
 
echo $file_contents;
 
?>
Copy after login


Related labels:
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