codice:
//list of browsers
$agentBrowser = array(
'Firefox',
'Safari',
'Opera',
'Flock',
'Internet Explorer',
'Seamonkey',
'Konqueror',
'GoogleBot'
);
//list of operating systems
$agentOS = array(
'Windows 3.1',
'Windows 95',
'Windows 98',
'Windows 2000',
'Windows NT',
'Windows XP',
'Windows Vista',
'Redhat Linux',
'Ubuntu',
'Fedora',
'AmigaOS',
'OS 10.5'
);
// is cURL installed yet?
if (!function_exists('curl_init')) {
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
//randomly generate UserAgent
$userAgent = $agentBrowser[rand(0, 7)] . '/' . rand(1, 8) . '.' . rand(0, 9) . ' (' . $agentOS[rand(0, 11)] . ' ' . rand(1, 7) . '.' . rand(0, 9) . '; en-US;)';
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow any redirects
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
/*curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);*/
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
echo $output;
Grazie per qualunque suggerimento.