Sometime we want to fetch the information from a domain. In PHP file_get_contents function would work fine. We can easily get few pages without getting blocked but if we want to circumvent few security measures then we have to use CURL with proxy and custom headers. Below is the example of custom headers :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
//get page source $url='https://google.com'; $headers = array( "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "ACCEPT_LANGUAGE: en-US,en;q=0.8,hi;q=0.6", "Cache-Control: no-cache", "CONNECTION: keep-alive", "HOST: google.com", "USER_AGENT: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36", "DNT: 1", ); $c=curl_init($url); curl_setopt($c,CURLOPT_RETURNTRANSFER,true); curl_setopt($c,CURLOPT_SSL_VERIFYHOST,false); curl_setopt($c,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($c,CURLOPT_HTTPHEADER,$headers); $response=curl_exec($c); curl_close($c); print_r(htmlentities($response)); |
The code for proxy will also be posted.