Advertisement
Guest User

Untitled

a guest
Feb 10th, 2012
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. public function fetchURL($url, &$stats = null, $isPost = false, $postParams = array())
  2. {
  3.     // Headers
  4.     $headers[]  = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
  5.     $headers[]  = 'Accept-Language: bg-BG,bg;q=0.8';
  6.     $headers[]  = 'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3';
  7.     $headers[]  = 'Cache-Control: max-age=0';
  8.     $headers[]  = 'Connection: keep-alive';
  9.    
  10.     // cURL
  11.     $curl   = curl_init();
  12.     curl_setopt($curl, CURLOPT_URL, $url);
  13.     curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.187 Safari/535.1");
  14.     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  15.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  16.     curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  17.     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  18.    
  19.     // Request type and params
  20.     curl_setopt($curl, CURLOPT_POST, $isPost);
  21.     if ($isPost)
  22.         curl_setopt($curl, CURLOPT_POSTFIELDS, $postParams);
  23.    
  24.     $cnt    = curl_exec($curl);
  25.     $stats  = curl_getinfo($curl);
  26.     curl_close($curl);
  27.    
  28.     // Result
  29.     return $cnt;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement