View Full Version : Checking to see if a site is updated

01-16-2008, 12:36 PM
I am using sha1_file() to see if a website has been updated. I have a bunch of website URLs stored in a mySQL db.

I have never done this before.. I thought if I ran a crontab every 24 hours and checked to see if the sha1_file($siteURL) encryption has changed then I will be able to inform myself that the website has been updated.

The code:

$sql = "SELECT siteURL, encryptedContent FROM acheckWebsite WHERE userid = {$_SESSION[userid]}";
// echo '<p>'.$sqlCountBkmark.'<p>';
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
$siteURL = $row[siteURL];
echo '<p>siteURL is: '.$siteURL.'</p>';
$encryptedContent = $row[encryptedContent];
$siteHash = sha1_file($siteURL);
echo '<p>siteHas is: '.$siteHash.'</p>';
if($encryptedContent == $siteHash){
// don't do anything, since nothing has not changed
// update the table with the new hash and email the user
$updateSiteHash = "UPDATE acheckWebsite SET encryptedContent='$siteHash' WHERE userid = {$_SESSION[userid]}";
echo '<p>'.$updateSiteHash.'</p>';
$resultSiteHash = mysql_query($updateSiteHash);
echo '<p>table updated with new hash</p>';
// mail notification to me that someone submitted a comment:
$fromnameComm = "myemail@yahoo.com";
$headers .= "From: \"".$fromnameComm."\" <".$fromaddressComm.">\n";
$email = "myemail@yahoo.com";
mail("$email","Website Update Notification","The following website has been changed. $siteURL ", $headers);


The problem arises that even if the website isn't changed the script ends up emailing me telling me that the site has changed. No changes have occurred, even the sha1 hash is the same.. what gives?

01-16-2008, 12:44 PM
The only thing I can see there is that $encryptedContent == $siteHash evaluates to FALSE .. perhaps put some more trace in to see what the values of $encryptedContent and $siteHash actually are?