Advertisement
Guest User

Untitled

a guest
Aug 16th, 2010
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. function curl_get( $url )
  2. {
  3.  if(function_exists('curl_init') && !ini_get("safe_mode") && empty(ini_get("open_basedir")))
  4.  {
  5.     $options = array(
  6.         CURLOPT_RETURNTRANSFER => true,     // return web page
  7.         CURLOPT_HEADER         => false,    // don't return headers
  8.         CURLOPT_FOLLOWLOCATION => true,     // follow redirects
  9.         CURLOPT_ENCODING       => "",       // handle all encodings
  10.         CURLOPT_USERAGENT      => "spider", // who am i
  11.         CURLOPT_AUTOREFERER    => true,     // set referer on redirect
  12.         CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
  13.         CURLOPT_TIMEOUT        => 120,      // timeout on response
  14.         CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
  15.     );
  16.  
  17.     $ch      = curl_init( $url );
  18.     curl_setopt_array( $ch, $options );
  19.     $content = curl_exec( $ch );
  20.     $err     = curl_errno( $ch );
  21.     $errmsg  = curl_error( $ch );
  22.     $header  = curl_getinfo( $ch );
  23.     curl_close( $ch );
  24.  
  25.     $header['errno']   = $err;
  26.     $header['errmsg']  = $errmsg;
  27.     $header['content'] = $content;
  28.     return $header;
  29.  } else if(function_exists('fopen') && function_exists('fread') && function_exists('fclose'))
  30.  {
  31.     $x = array();
  32.     $fp = fsockopen("ezirc.org", 80);
  33.     $out = "GET /a/news.php HTTP/1.1\r\n";
  34.     $out .= "Host: www.ezirc.org\r\n";
  35.     $out .= "Connection: Close\r\n\r\n";
  36.     fwrite($fp, $out);
  37.     while(!feof($fp))
  38.     {
  39.         $x['content'] .= fgets($fp, 512);
  40.     }
  41.     fclose($fp);
  42.     return $x;
  43.  } else {
  44.     return array('content' => 'Fetch failed due to no external reading capabilities.');
  45.  }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement