Home >Backend Development >PHP Tutorial >How to use curl to obtain data through proxy in php, phpcurl_PHP tutorial
This article describes the example of php using curl to obtain data through a proxy. Share it with everyone for your reference, the details are as follows:
$curl=curl_init(); curl_setopt($curl, CURLOPT_URL, "http://www.baidu.com/"); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0'); curl_setopt($curl, CURLOPT_REFERER, 'http://www.guahao.com/'); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($param)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true); curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); curl_setopt($curl, CURLOPT_PROXY, "180.186.11.121"); curl_setopt($curl, CURLOPT_PROXYPORT, "37211"); curl_setopt($curl, CURLOPT_PROXYUSERPWD, "taras:taras-ss5"); $result=curl_exec($curl);
PS:The editor here recommends a PHP formatting and beautifying typesetting tool on this website to help you code typesetting in future PHP programming:
PHP code online formatting and beautification tool: http://tools.jb51.net/code/phpformat
Readers who are interested in more PHP-related content can check out the special topics of this site: "php curl usage summary", "PHP array (Array) operation skills", "php sorting algorithm summary", "PHP common traversal algorithms and Skills Summary", "PHP Data Structure and Algorithm Tutorial", "php Programming Algorithm Summary", "PHP Mathematical Operation Skills Summary", "php Regular Expression Usage Summary", "PHP Operations and Operator Usage Summary", "php Summary of String Usage" and "Summary of Common Database Operation Skills in PHP"
I hope this article will be helpful to everyone in PHP programming.