Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. private function get_web_page($url)
  2.     {
  3.         $user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
  4.  
  5.         $options = array(
  6.  
  7.             CURLOPT_CUSTOMREQUEST => "GET",        //set request type post or get
  8.             CURLOPT_POST => false,        //set to GET
  9.             CURLOPT_USERAGENT => $user_agent, //set user agent
  10.             CURLOPT_COOKIEFILE => "cookie.txt", //set cookie file
  11.             CURLOPT_COOKIEJAR => "cookie.txt", //set cookie jar
  12.             CURLOPT_RETURNTRANSFER => true,     // return web page
  13.             CURLOPT_HEADER => false,    // don't return headers
  14.             CURLOPT_FOLLOWLOCATION => true,     // follow redirects
  15.             CURLOPT_ENCODING => "",       // handle all encodings
  16.             CURLOPT_AUTOREFERER => true,     // set referer on redirect
  17.             CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
  18.             CURLOPT_TIMEOUT => 120,      // timeout on response
  19.             CURLOPT_MAXREDIRS => 10,       // stop after 10 redirects
  20.         );
  21.  
  22.         $ch = curl_init($url);
  23.         curl_setopt_array($ch, $options);
  24.         $content = curl_exec($ch);
  25.         $err = curl_errno($ch);
  26.         $errmsg = curl_error($ch);
  27.         $header = curl_getinfo($ch);
  28.         curl_close($ch);
  29.  
  30.         $header['errno'] = $err;
  31.         $header['errmsg'] = $errmsg;
  32.         $header['content'] = $content;
  33.         return $header;
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement