andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Small version without mysql available?
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> WWW Checkup
View previous topic :: View next topic  
Author Message
Conny
Newbie


Joined: 05 Jul 2005
Posts: 8

PostPosted: Tue Jul 05, 2005 2:45 pm    Post subject: Small version without mysql available? Reply with quote

What a pitty, i have no mysql, it would be nice, to have a small one, without mysql...
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Tue Jul 05, 2005 5:14 pm    Post subject: Reply with quote

Hi Conny, and welcome to the board.

Easy enough! Just requires a little tweaking of the class so that you use the file system rather than the database.

Here's a little something I just whipped up and briefly tested. Seems to work just fine.

PHP:
<?php

//
// class.wwwcheckup.php
//
// Description
//
// This class allows you to keep track of when websites were last updated.
// This will not tell you what the changes are, but just let you know that
// it has been changed in some way.
//
// Author
//
// Andrew Collington, 2005
// php@amnuts.com, http://php.amnuts.com/
//
// Feedback
//
// http://php.amnuts.com/forums/index.php
// There is message board at the above URL where you can post
// feedback, bug reports, feature requests, etc., for this and
// any of the other scripts located at php.amnuts.com.
//
// This script would be most efficiently used in conjunction with a cron job
// to automatically check the status of the pages, so that all you have to
// do is show the results.
//

class WebsiteCheckup
{
    var 
$filename;
    var 
$autoupdate;
    var 
$sites;
    var 
$results;
    
    function 
WebsiteCheckup($filename 'sites.txt')
    {
        
$this->filename   $filename;
        
$this->autoupdate true;
    }
    
    function 
SetAutoUpdate($status true)
    {
        
$this->autoupdate = ($status === true true false);
    }

    function 
CheckAll()
    {
        if (empty(
$this->sites)) {
            
$this->GetAll();
        }
        foreach (
$this->sites as $url => $info) {
            
set_time_limit(120);
            
$content = @file($url);
            if (empty(
$content)) {
                echo 
"<p>The website $site could not be fetched.</p>\n";
            } else {
                
$hash md5(strip_tags(join(''$content)));
                if (
$this->autoupdate) {
                    if (
$hash != $info['hash']) {
                        
$this->results[$url] = $this->sites[$url];
                        
$this->sites[$url]['hash'] = $hash;
                        
$this->sites[$url]['checked'] = time();
                        
$this->sites[$url]['updated'] = time();
                    } else {
                        
$this->sites[$url]['checked'] = time();
                    }
                } else {
                    if (
$hash != $info['hash']) {
                        
$this->results[$url] = $this->sites[$url];
                    }
                }
            }
        }
        if (
$this->autoupdate) {
            
$this->UpdateFile();
        }
    }
    
    function 
GetAll()
    {
        
$this->sites = array();
        if (
file_exists($this->filename)) {
            
$this->sites unserialize(file_get_contents($this->filename));
        }
    }
    
    function 
UpdateFile()
    {
        
$content '';
        if (!empty(
$this->sites)) {
            
$fp fopen($this->filename'w'));
            if (
$fp !== false) {
                
fwrite($fpserialize($this->sites);
                
fclose($fp);
                return 
true;
            }
        }
        return 
false;
    }
    
    function 
AddWebsite($website '')
    {
        if (
$website == '') {
            return;
        }
        
        if (!
preg_match('/^http:\/\//i'$website)) {
            
$website "http://{$website}";
        }

        
$site = array();
        
set_time_limit(120);
        
$site = @file($website);
        if (empty(
$site)) {
            return 
false;
        } else {
            
$this->sites[$website] = array('hash' => md5(strip_tags(join(''$site))), 'checked' => time(), 'updated' => time());
            return (
$this->UpdateFile());
        }
    }
    
    function 
RemoveWebsite($website '')
    {
        if (
$website == '') {
            return 
false;
        }

        if (!
preg_match("/^http:\/\//i"$website)) {
            
$website "http://{$website}";
        }

        unset(
$this->sites[$website]);
        return (
$this->UpdateFile());
    }

    function 
DisplayUpdates()
    {
        
$this->CheckAll();
        
$this->DisplayTable($this->results);
    }

    function 
DisplayAll()
    {
        
$this->GetAll();
        
$this->DisplayTable($this->sitestrue);
    }

    function 
DisplayTable($array$colour false)
    {
        if (empty(
$array)) {
            echo 
"<p>There are no websites or results available.</p>\n";
        } else {
            echo 
'<table>'"\n";
            echo 
'<thead><tr><td>website</td><td>last checked</td><td>last updated</td></tr></thead><tbody>'"\n";
            foreach (
$array as $url => $info) {
                if (
$colour && ($info['checked'] == $info['updated'])) {
                    
$bg ' style="background-color:#CCC;"';
                } else {
                    
$bg '';
                }
                echo 
"<tr{$bg}><td><a href=\"$url\" target=\"_blank\">$url</a></td>";
                echo 
"<td>"$this->FuzzyTime($info['checked']), '</td>';
                echo 
"<td>"$this->FuzzyTime($info['updated']), "</td></tr>\n";
            }
            echo 
"</tbody></table>\n";
        }
    }

    function 
FuzzyTime($time)
    {
        
// sod = start of day Smile
        
$sod mktime(000date('m',$time), date('d'$time), date('Y'$time));
        
$sod_now mktime(000date('m'), date('d'), date('Y'));
        
        if (
$sod_now == $sod) return "today at " date("g:ia"$time); // check 'today'
        
if (($sod_now-$sod) <= 86400) return "yesterday at " date("g:ia"$time); // check 'yesterday'
        
if (($sod_now-$sod) <= 432000) return date("l \a\\t g:ia"$time); // give a day name if within the last 5 days
        
if (date("Y",$now) == date("Y"$time)) return date("M j \a\\t g:ia"$time); // miss off the year if it's this year
        
return date("M j, Y \a\\t g:ia"$time); // return the date as normal
    
}
    
}

?>


Instantiates with only the filename that you want to store the results in, or no parameter to use 'sites.txt' in the local directory to the class.

Enjoy!

Andy


Last edited by amnuts on Thu Jul 07, 2005 10:26 am; edited 3 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Conny
Newbie


Joined: 05 Jul 2005
Posts: 8

PostPosted: Thu Jul 07, 2005 4:26 am    Post subject: Reply with quote

Hello Andy!
Many thanks for the quick answer...
The idea for this program is great!

I put your (upper) new code in the class.wwwcheckup.php file,
put in the same directory a file named sites.txt (chmod777)
and start test.www.checkup.php

Add some demo sites - return message: Adding... succsessful

List all websites - message: There are no websites or results available.

The file sites.txt is empty...

It does'nt work - what's wrong? (I am php-newbie)

Conny
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Jul 07, 2005 6:00 am    Post subject: Reply with quote

I just tweaked the above class, specifically the UpdateFile() and AddWebsite() methods, to give a more accurate feedback of success or not. So make sure you copy it again.

Now, why is it not working? Hmm... My first thought would have been permission, but you say you have done that. Make sure the folder has write permissions for the web server if you're starting the class and sites.txt (or whatever your file is called) doesn't exist.

Try also instantiating the class with the full path to the file (including the filename, naturally), rather than just relative. So something like this:

$obj =& new WebsiteCheckup(dirname(__FILE__) . '/sites.txt');

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Conny
Newbie


Joined: 05 Jul 2005
Posts: 8

PostPosted: Thu Jul 07, 2005 8:08 am    Post subject: Reply with quote

Hello Andy

The demosites are stored in a file named "demouser"
Now -List all websites- possible.
It seems it works - but it show always the current time.

Many thanks
Conny
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Jul 07, 2005 9:31 am    Post subject: Reply with quote

Conny wrote:
The demosites are stored in a file named "demouser"
Now -List all websites- possible.
It seems it works - but it show always the current time.


That's only to be expected! If you add the websites in one go using the test file, and then list the sites you'll see when the site was last checked and updated. But seeing as you've only ever checked it once, the updated date is going to be the same time.

Once you've added the websites, wait a while (or add a website you can change the content on at any time) and then check again with the option to make changes to the database. Then list the sites again.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Conny
Newbie


Joined: 05 Jul 2005
Posts: 8

PostPosted: Thu Jul 07, 2005 9:45 am    Post subject: Reply with quote

Hi Andy!

Look here:

http://www.wicom.at/steam/test/test.wwwcheckup.php?noupdate=1

Its different from your live-demo...

Conny
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Jul 07, 2005 10:02 am    Post subject: Reply with quote

Hmm.. I see what you mean?

What PHP version are you using and on what platform? Maybe there's something there.

Check the data file; it's mean't to have the format:

[url][tab][hash][timestamp][tab][timestamp][newline]

If it doesn't, then that might account for it going pear-shaped.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Conny
Newbie


Joined: 05 Jul 2005
Posts: 8

PostPosted: Thu Jul 07, 2005 10:06 am    Post subject: Reply with quote

Hi Andy

The Datefile: al line look like:

http://php.amnuts.com/forums/index.php b4f69815c63ea807b5d0f061dec2e27c 1120748164 1120748164

Conny
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Jul 07, 2005 10:06 am    Post subject: Reply with quote

Okay, that file format is silly when I coul djust store a serialized array! So I tweaked the above class again, this time the GetAll and UpdateFile methods to use a serialized array instead.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Jul 07, 2005 10:33 am    Post subject: Reply with quote

Conny wrote:
Hi Andy

The Datefile: al line look like:

http://php.amnuts.com/forums/index.php b4f69815c63ea807b5d0f061dec2e27c 1120748164 1120748164

Conny


Well, that seems to be saving the data file okay. And I don't see anything obvious in the class that would make it not function correctly... And the odd thing is, it seems to be working fine for me.

http://php.amnuts.com/test/webcheck/

I use the class copied and pasted directory from the message above, and this as the test file@

PHP:
<?php

include('checkup.php');

$cu =& new WebsiteCheckup();

if (isset(
$_GET['add']))
{
    echo 
"Adding http://php.amnuts.com/ - ", ($cu->AddWebsite("http://php.amnuts.com/")?"succesful":"failed"), "<br />\n";
    echo 
"Adding http://php.amnuts.com/forums/index.php - ", ($cu->AddWebsite("http://php.amnuts.com/forums/index.php")?"succesful":"failed"), "<br />\n";
    echo 
"Adding http://amnuts.talker.com/cgi-bin/AMboard/UltraBoard.pl - ", ($cu->AddWebsite("http://amnuts.talker.com/cgi-bin/AMboard/UltraBoard.pl")?"succesful":"failed"), "<br />\n";
    echo 
"Adding http://www.hotscripts.com/ - ", ($cu->AddWebsite("http://www.hotscripts.com/")?"succesful":"failed"), "<br />\n";

}

if (isset(
$_GET['checkup']))
{
    
$cu->SetAutoUpdate(true);
    
$cu->DisplayUpdates();
    echo 
"<br><br>\n\n";
}

if (isset(
$_GET['list']))
{
    
$cu->DisplayAll();
    echo 
"<br><br>\n\n";
}

if (isset(
$_GET['noupdate']))
{
    
$cu->SetAutoUpdate(false);
    
$cu->DisplayUpdates();
    echo 
"<br><br>\n\n";
}

echo 
"<hr noshade>\n";
echo 
"<p><a href=\"{$_SERVER['PHP_SELF']}?add=1\">Add some demo sites</a></p>\n";
echo 
"<p><a href=\"{$_SERVER['PHP_SELF']}?list=1\">List all websites (no updating)</a></p>\n";
echo 
"<p><a href=\"{$_SERVER['PHP_SELF']}?checkup=1\">Check for updates (and make changes in database)</a></p>\n";
echo 
"<p><a href=\"{$_SERVER['PHP_SELF']}?noupdate=1\">Check for changes (and make no changes in database)</a></p>\n";

?>
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Conny
Newbie


Joined: 05 Jul 2005
Posts: 8

PostPosted: Thu Jul 07, 2005 10:41 am    Post subject: www.checkup Reply with quote

Your link:
http://php.amnuts.com/test/webcheck/index.php?list=1
I see:
website last checked last updated
http://php.amnuts.com/ today at 11:34am today at 11:29am
http://php.amnuts.com/forums/index.php today at 11:34am today at 11:34am
http://amnuts.talker.com/cgi-bin/AMboard/UltraBoard.pl today at 11:34am today at 11:29am
http://www.hotscripts.com/ today at 11:34am today at 11:30am

for today its over - I try it from another host
til tomorrow

Conny
Back to top
View user's profile Send private message
Conny
Newbie


Joined: 05 Jul 2005
Posts: 8

PostPosted: Thu Jul 07, 2005 11:19 pm    Post subject: Trying with your "checkup-file" Reply with quote

Good morning Andy!

Trying with your "checkup"-file:
Parse error: parse error, unexpected ')' in /home/.../classwwwcheckup.php on line 92

Conny
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Fri Jul 08, 2005 2:05 am    Post subject: Reply with quote

I had missed off a ) in the code when I tweaked it yesterday. On, or around line 92 you'll find:

fwrite($fp, serialize($this->sites);

Make it:

fwrite($fp, serialize($this->sites));

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Conny
Newbie


Joined: 05 Jul 2005
Posts: 8

PostPosted: Fri Jul 08, 2005 3:56 am    Post subject: Reply with quote

Hi Andy!

I think I make you a lot of trouble...

The error now:
Parse error: parse error, unexpected ')' in /home/www/web127/html/regatta-bodensee.com/wwwcheckup/class.wwwcheckup.php on line 92

Conny
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> WWW Checkup All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group