Log in

View Full Version : New script



nikomou
05-08-2006, 09:14 AM
Hi,

Does anybody now how to make a php script that will send out an email when a page/website has been updated?

What i have in mind is saving the page as a txt file on my server (compare_site.txt), and every so often save as a new txt file (compare_new.txt) if they both match, do nothing.. if there has been a change, send an email, and copy compare_new.txt to compare_site.txt, then continue....

djr33
05-08-2006, 09:19 AM
when a page/website has been updated?Details? If you're updating it, then why would you need to be notified? Or, do you mean other people have access?

Hmm.... I think it makes sense... but... there's an issue.

You are wanting an automatic action serverside, but you really need to access php through a browser. The best way is to check it when the .txt is updated. Or you could check every time someone access a particular page on your site. You need to pick WHEN the check will occur. That's important.


Here's some code that will help to compare:

<?
$1 = file_get_contents('1.txt');
$2 = file_get_contents('2.txt');
if ($1 != $2) {
echo "They do not match.";
}
?>

It will be more complex, but that checks if they are the same.


Sending an email is just using the mail() function. There are odd security things here as well as some complex setup things due to differing servers.

Assuming it just works in the normal way, then you can just use the example on http://php.net (search "mail" in the text box).

Twey
05-08-2006, 03:42 PM
You need to use cron (or whatever Windows has instead) for this anyway, so you may as well go the whole hog and just use shell scripting:

diff compare_site.txt compare_new.txt &> /dev/null
&& exit
|| echo "The site has been updated." | mail -s "Site Update Alert" 'address@domain.com';

nikomou
05-09-2006, 10:44 AM
Its not a website that i am updating, i just want an email to know when the page has change...

Twey
05-09-2006, 03:50 PM
The messages don't matter :) It'll notify you when the files differ. You can change the messages to whatever takes your fancy.