I download a file via curl every 10mins as the site needs authentication and doesn't have RSS for updates.
If the file is different (HTML code) then I want to email it to myself to have a look.
I tried this but it doesn't seem to compare the files - it seems even though the file is the same, curl adds or takes off a few bytes here and there for the filesize. Can I somehow compare the HTML string without spaces?
Any ideas?
Full code:
#! /usr/bin/php
<?php
$fh = fopen("/usr/local/sbin/myscripts/ITMS_PTWL.html", 'w') or die("can't open file fh");
//INIT CURL
$ch = curl_init();
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL,
'https://www.inthemoneystocks.com/login.php');
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS,
'_username=MYUSERN&password=MYPASSWORD');
// IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);
// SET FILE TO DOWNLOAD
curl_setopt($ch, CURLOPT_URL,
'https://www.inthemoneystocks.com/pro_trader_watch_list_prem.php');
// EXECUTE 2nd REQUEST (FILE DOWNLOAD)
$content = curl_exec ($ch);
fwrite($fh, $content);
fclose($fh);
// CLOSE CURL
curl_close ($ch);
$to = 'webster_jack@hotmail.com';
$subject = 'Pro Trader Watchlist';
$random_hash = md5(date('r', time()));
$headers = "From: webmaster@proxyplayer.co.uk\r\nReply-To: webmaster@proxyplayer.co.uk";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<?
$page = file_get_contents('/usr/local/sbin/myscripts/ITMS_PTWL.html');
echo $page;
?>
--PHP-alt-<?php echo $random_hash; ?>--
<?
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
?>