Hi there, below is a little snippet of what using Proxy in PHP cURL
1 |
<pre><br /><span style="background: #ffffe8; color: #5f5035;"><?php</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #797997;">$loginpassw</span><span style="background: #ffffe8; color: black;"> </span><br /><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #0000e6;">''</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: dimgrey;">//your proxy login and password here if any</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #797997;">$proxy_ip</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #0000e6;">'202.148.22.171'</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: dimgrey;">//proxy IP here</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #797997;">$proxy_port</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">80</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: dimgrey;">//proxy port from your proxy list</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #797997;">$url</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #0000e6;">''</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: dimgrey;">//URL to get</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: dimgrey;">//Lets initiate cURL</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #400000;">curl_init</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: dimgrey;">//Some useful things we need for it to work</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #400000;">curl_setopt</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #7d0045;">CURLOPT_URL</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #797997;">$url</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #400000;">curl_setopt</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #7d0045;">CURLOPT_HEADER</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">0</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: dimgrey;">// no headers in the output</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #400000;">curl_setopt</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #7d0045;">CURLOPT_RETURNTRANSFER</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">1</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: dimgrey;">// output to variable</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #400000;">curl_setopt</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> CURLOPT_PROXYPORT</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #797997;">$proxy_port</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #400000;">curl_setopt</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> CURLOPT_PROXYTYPE</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #0000e6;">'HTTP'</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #400000;">curl_setopt</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #7d0045;">CURLOPT_PROXY</span><span style="background: #ffffe8; color: #808030;">,</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #797997;">$proxy_ip</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: dimgrey;">//Gather up every result in a variable</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #797997;">$data</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #400000;">curl_exec</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: dimgrey;">//We are done, lets close connection</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #400000;">curl_close</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #797997;">$ch</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: dimgrey;">//Show up your result</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: maroon; font-weight: bold;">echo</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #797997;">$data</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #5f5035;">?></span><br /> |