public
Created

Simple Curl function for retrieving a remote url

  • Download Gist
curl.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?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);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.