Home > API Shares, internet, OFFER, Open-source, PHP, Wordpress > DownloadUrlContent from other site using Curl Method

DownloadUrlContent from other site using Curl Method

function DownloadUrlContent($Url,$fields=array(”)){
if (!function_exists(‘curl_init’)){
die(‘CURL is not installed!’);
}
$ch        =    curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_REFERER, “http://www.google.com/”);
curl_setopt($ch, CURLOPT_USERAGENT,’Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18′);
curl_setopt($ch, CURLOPT_HTTPHEADER,array(‘Expect:’));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
if(count($fields)>0){
foreach($fields as $key=>$value) { @$fields_string .= trim($key).’=’.trim($value).’&’; }

rtrim(trim($fields_string),’&’);
$fields_string    =    substr($fields_string,0,strlen($fields_string)-1);

curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
}
$output = curl_exec($ch);
curl_close($ch);
return $output;
}

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: