×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: PHP
Posted by: A973C FR
Added: Sep 24, 2012 5:26 AM
Modified: Sep 24, 2012 5:27 AM
Views: 61
Tags: php curl
  1.     function xcurl($url,$ref=null,$post=array(),$ua="Mozilla/5.0 (X11; Linux x86_64; rv:2.2a1pre) Gecko/20110324 Firefox/4.2a1pre",$print=false) {
  2.     $ch = curl_init();
  3.     curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  4.     if(!empty($ref)) {
  5.     curl_setopt($ch, CURLOPT_REFERER, $ref);
  6.     }
  7.     curl_setopt($ch, CURLOPT_URL, $url);
  8.     curl_setopt($ch, CURLOPT_HEADER, 0);
  9.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  10.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  11.     if(!empty($ua)) {
  12.     curl_setopt($ch, CURLOPT_USERAGENT, $ua);
  13.     }
  14.     if(count($post) > 0){
  15.     curl_setopt($ch, CURLOPT_POST, 1);
  16.     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  17.     }
  18.     $output = curl_exec($ch);
  19.     curl_close($ch);
  20.     if($print) {
  21.     print($output);
  22.     } else {
  23.     return $output;
  24.     }
  25.     }