// Do all your mysql_connect() stuff up here
$content = file_get_contents('https://club.nintendo.com/rewards.do');
if (stristr($content, 'Sign In to Club Nintendo'))
{
$content = trimString($content, '<div id="content"', '<!-- #content -->');
$hash = md5(trim(strip_tags($content)));
$query = "SELECT ID AS ID, " .
" Hash AS Hash " .
"FROM ClubNintendo " .
"ORDER BY StateDateTime DESC " .
"LIMIT 1 ";
$result = mysql_query($query);
list($previousID, $previousHash) = mysql_fetch_row($result);
mysql_free_result($result);
if ($previousHash == $hash && is_numeric($previousID))
{
$query = "UPDATE LOW_PRIORITY ClubNintendo " .
"SET LastTested=NOW() " .
"WHERE ID=$previousID ";
mysql_query($query);
}
else if ($previousHash != $hash)
{
$subject = "Club Nintendo update";
$message = "Looks like stuff has changed at https://club.nintendo.com/rewards.do !";
$recipients = array('[my phone's email->text address]', '[my personal email]');
mailMessage($recipients, $subject, $message);
$query = "INSERT INTO ClubNintendo " .
"(ID, Hash, StateDateTime) VALUES (NULL, '" . addslashes($hash) . "', NOW()) ";
mysql_query($query);
}
}
function trimString($string, $start, $end)
{
$startPosition = strpos($string, $start);
if ($startPosition === false)
return (false);
$string = substr($string, $startPosition + strlen($start));
$endPosition = strpos($string, $end);
if ($endPosition === false)
return (false);
$string = substr($string, 0, $endPosition);
return trim($string);
}