Skip to content

Instantly share code, notes, and snippets.

@timw4mail
Created October 26, 2011 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timw4mail/1315076 to your computer and use it in GitHub Desktop.
Save timw4mail/1315076 to your computer and use it in GitHub Desktop.
Simple Curl function for retrieving a remote url
<?php
function do_curl($url, $options=array())
{
$cookie = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init($url);
//Use the user's User Agent and Cookies
$opts= array(
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
CURLOPT_COOKIEJAR => $cookie,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_MAXREDIRS => 10,
CURLOPT_PROTOCOLS => array(CURLPROTO_HTTP,CURLPROTO_HTTPS)
);
$options = array_merge($opts, $options);
curl_setopt_array($ch, $options);
return curl_exec($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment