0

I need script that sends me email when something changes on page. This is my code but it's not working correct. How can i do this to work properly?

$new_page = file_get_contents('http://www.google.com');

$new_page_in = mysql_real_escape_string($new_page);
mysql_query("UPDATE new SET text='$new_page_in' WHERE id='1'") or die (mysql_error());

$sql1 = mysql_query("SELECT text FROM new WHERE id='1'") or die (mysql_error());
list($new_out) = mysql_fetch_row($sql1);

$sql2 = mysql_query("SELECT text FROM old WHERE id='1'") or die (mysql_error());
list($old_out) = mysql_fetch_row($sql2);    

if($new_out != $old_out)
{
    $new_page = file_get_contents('http://www.google.com');
    $new_page_in = mysql_real_escape_string($new_page);
    mysql_query("UPDATE old SET text='$new_page_in' WHERE id='1'") or die (mysql_error());
    echo "Text is diferent.";
            //send email
}
else
{
    echo "Text isn't diferent";
}
tshepang
  • 12,111
  • 21
  • 91
  • 136

2 Answers2

0

Try using the comparison

strcmp($new_out, $old_out) == 0

to test if they are the same.

Also I would suggest just storing a hash of the page content in the database instead of the entire string. So store

hash('md5', $new_page) 

in the database instead of $new_page and compare hashes if you want to see if anything has changed. Store the content as well if you need to, but don't compare on the contents.

Ansari
  • 8,168
  • 2
  • 23
  • 34
0

I will suggest while storing the htmlcontent add htmlentities and also remove all the whitespaces before before storing.... You can refer to this link for the regex to do the same....

Also you can make use of the string algorithms like levenshtein or similar-text to check the matching percentage and keep some threshold maybe 95% for almost same

Community
  • 1
  • 1
swapnilsarwe
  • 1,290
  • 1
  • 8
  • 13