Results 1 to 5 of 5

Thread: New script

  1. #1
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default New script

    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....

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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:
    PHP Code:
    <?
    $file_get_contents('1.txt');
    $
    file_get_contents('2.txt');
    if ($
    != $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).

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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:
    Code:
    diff compare_site.txt compare_new.txt &> /dev/null
      && exit
      || echo "The site has been updated." | mail -s "Site Update Alert" 'address@domain.com';
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Its not a website that i am updating, i just want an email to know when the page has change...

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The messages don't matter It'll notify you when the files differ. You can change the messages to whatever takes your fancy.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •