Posted by:
toivo
(---.belrs4.nsw.optusnet.com.au)
Hi,
Here is sample code from a subroutine called in a command line script which works under Wampserver 5:
$site_url = 'http://example.com';
$user_agent = ' Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12');
@$ch = curl_init();
if ($ch === false) {
$msg = "\nAn error has occurred in getting a curl handle\n";
$message .= $msg;
$result = array(false, $message);
return $result;
}
// echo "curl_init done\n";
curl_setopt($ch, CURLOPT_URL, $site_url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
// output to file
curl_setopt($ch, CURLOPT_FILE, $page_write);
@curl_exec($ch);
$errnum = curl_errno($ch);
closeFile($page_write);
// echo "exec closefile done\n";
$status_line = '';
$run_status = true;
if ($errnum != 0) {
$run_status = false;
$status_line = $site_url." : status: ".$errnum." - DOWN\n";
}
$message .= $status_line;
// read file contents
$php_version = PHP_VERSION;
if (substr($php_version, 0, 1) > "4"
{
$page = file_get_contents($webpage_file);
} else {
$line_array = array();
$line_array = file($webpage_file, FILE_IGNORE_NEW_LINES);
$page = '';
foreach ($line_array as $line) {
$page .= $line;
}
}
echo $page;
Enjoy!
Regards,
toivo
Sydney, Australia
Edited 2 time(s). Last edit at 04/04/2008 11:40AM by toivo.