Frames Modems Help Home Page Chipsets Search No Frames
Diary Entries See also Site Info & Diary.
08 March 2002 Do you ever get that ‘Doh’ feeling? [implementing Stats info]...
  I do.

Most recently was whilst looking through some web-pages of a bloke who provides a free Java Counter.

  On 4 Feb the people at TheCounter.com, who previously had provided me with a free counter, had demanded $587.45 to continue the service. This really was too much & I declined their offer. Nevertheless, I missed knowing how many hits the site was getting.

Back on about the 16 Aug I had come across uklinux.net & had signed up with them, getting 20 MB of free webspace with PHP & MySQL facilities in the process. I've been spending the last 6+ months building a database-driven version of my site. Most recently, as an example, adding 200+ Conexant/Rockwell chipsets. In fact, I've become totally bloody (and mindfully) obsessed with getting all this ready for transport across to the UKLinux servers (another couple of months to go yet), even establishing new domains with them.

Then, yesterday, at work I was given a link for finding the status of jobs we had booked & was amused to see that the counters that they had on the site were blank (probably because of my company's Firewall), and went to look at the provider of the Counter, getting interested because it was free. As I looked at his pages, making mental comparisons of his page hits with mine & all the rest (mine's bigger than yours), I realised that he must be running a database on his site & using JavaScript to move vertical strips of GIF images of numbers to provide the picture of page hits etc etc...

At this point I had my ‘Doh’ moment.

I've got a site with database facilities & the ability to track how many hits my pages get. I don't need anybody else to do it for me. I've been waiting until I transfer it all across, but I can implement that part of it now, if I want to. Doh!!!

  This page is the first to test it all out. If you see stats at the bottom of the page, it is working (and will be transferred to every other page - eventually). Don't worry if it is not there - I may be adding functionality to it right now!

The only concern at this stage is that, whilst these pages are on Freeserve, it draws the stats & mailing links via an IFRAME from another domain - not good policy. The stats, however, have always been drawn from another domain, so in reality there is no difference there. Even this concern will melt away when these pages are transferred to the UKLinux domain.

For those with privacy concerns...

The database is at 14 Jan (stats) - you will see that no personal info of any concern whatsoever is stored, purely numbers of pages viewed & date.

09 March 2002 Update, at about 10 pm GMT...
  The whole site now has a stats page, and it appears to be working fine with the sole exception of reporting the page date.

A scrap of JavaScript is used to pick up the last-modified date of the main page then another scrap of script on the stats section should report that date. Experimenting on my own computer the date showed fine, but when I looked at the pages across the net it did not. The difference, I think, is because of Frames, which were active across the net but not used locally, apart from the IFrames which allow the stats in the first place. If I'm willing to take the time (not at the moment) this can be fixed. I've just had a look through the Java Object tree (Objects, Properties & Methods hyperlinked to descriptions) - something I've constructed on my own computer, and which I keep thinking would be useful to make available, but never get the time to do.

I also needed to add the facility to show the stats on a white background (certain help pages as one example) or to silently store the stats but not report anything. This latter is useful for certain pages:

  • Guest pages (eg Alan Fowler's or the WebBoy)
  • “Page Moved” pages
  • Mail & other pages
The UK Linux server offers phpMyAdmin 2.2.0 which allows online administration of MySQL - very useful, although most tempting to add a couple of million hits!!! I had a quick look shortly before writing this, a little less than 24 hours after putting up this page & about 18 hours after changing all the pages. 226 separate pages had been viewed (3 for yesterday, all the rest for today). Someone was busy reading these diary pages as I did the first mass uplift, so they are the first records stored, just one view each. The WebBoy page was the second record & also proves to be more popular than I expected. Certain pages already have up to or over a thousand hits each, and this is the very best aspect of the stats - I never knew before how many hits each page got, and now I can get a fuller picture.

A couple of things have surprised me. First is that some clever sod has tried to hack or otherwise affect the server - how else can you explain a page hit on “mfc/mailto:webmaster”? I've got measures in place to prevent this (see 14 Dec) but I'm amazed that the attempt comes less than 24 hours after putting the stats in place. Second is the number of hits on “Page Moved” pages. One of these was moved almost 2 years ago & had 2 hits on it.

Finally, I'm going to put a graphical display of hits into place. This will be useful for others as well as myself, plus prove that I'm not manipulating the figures. A good days work so far, I think.

15 March 2002 Full Stats in place, in spite of collapsing curtains...
  Sunday is my ‘Monday’ - the first day of my working week. Closing (it might have been opening) the curtains in my front room on this day the far left-hand part of the curtain rail came away from the wall & then, presumably in sympathy, almost all of the rest of the rail followed the LHS in descent towards the floor

My front window is an 8 foot diameter bay-window. A monstrous size (in English terms) with a curtain rail - sorry, former curtain rail - 100 inches from the floor & 6 foot high windows. The weight of lined-curtains that shields/decorates this size of window is truly awesome, and when first bought some 15 years ago I had taken the precaution of purchasing a steel curtain rail. As I now stood dumbstruck with curtains in hand, one end of the rail bravely clinging to it's batten but the other forlornly drooping to the floor, it was clear what the rest of my week was going to be filled with.

You may have noticed that the measurements above are in feet & inches. This will seem natural to you if American, and peculiar if European or British below 30 years or so of age. I'm over 50, and it was excellent to go to America last summer and discover a land that still has Fahrenheit & gallons & feet & inches. Britain - former home of the Imperial Measure - is now half and half, as the bureaucrats (b-euro-crats) drag it kicking and screaming towards the land of the Metre, the Litre & other intellectual nonsenses. Most windows are still in feet & inches. The curtain manufacturers have therefore compromised - heights of curtains are in inches, whilst their widths are in centimetres. This meant that the sales assistant & myself had to work as a team. She - being under 30 - did not understand feet and needed a calculator to convert the widths I presented into centimetres. I, being thick, did not understand what window a set of curtains 264cm wide x 229cm drop could possibly fit. I also needed a great deal of assistance & help to understand why these ready-made curtains would cost me £299. Made-to-measure would have taken 5 weeks and approaching £1000 (the rear windows needed a matching set too).

I have an interesting life (in the sense of the Chinese insult). This was clearly the time to paint the battens, of which there are 3. Rummaging in my basement I found all that I needed, including a tin of Brilliant White gloss, but also of Mountain Ash. This latter looked in the light of the single bulb like an interesting shade of grey. When I brought everything upstairs into the living room, and the tin slipped off to the floor, and the lid came off & gloss paint spilt all over the carpet, it proved to be a disgusting shade of green. Nice name, though. For the last few years I have been storing up all my old shirts, ready for a time just like this. It took 5 of them plus half a bottle of White Spirit to remove the paint. There is now a very clean patch in the carpet (with a slight green tinge) which nicely shows up just how much the rest needs cleaning.

One of the 3 battens was loose. I removed it, and discovered behind that... I really don't need to go on, do I?

  In between all of the above excitement I have been putting a page showing full page stats in place. This works and looks really good.

What is most peculiar is that I have had two more pages called ‘mailto:webmaster’ appear in the listing - 4 in total now in one week. I've checked & re-checked, but have no idea at all where they come from. Also a page consisting of a single space. If you discover the reason for these mysteries, do let me know; they could well be attempted hacks, who knows? I've sorted my mind out on the issue of people trying to hack the database. Anyone with a home has to arrange their mind as to it's security. This is a simple practical matter, and not a reason for emotional whoopsies, no matter what. “Do what is necessary” is the creed. Same with the Database.

25 March 2002 My stats threatens the whole of the Subscription server...
  ...so the server Techs put a stop to it. Almost 24 hours of stats was lost on Friday/Saturday.

At this moment of writing I still do not know why, but the server logs showed that the server was almost at full load, and my little script was responsible. Yikes (sorry Jason). The first I knew of it was the wee hours of Saturday morning when I came across the message:

    Warning: Failed opening '/..(the path)../stats.php' for
    inclusion (include_path='.:/usr/share/php') in Unknown on line 0
at the bottom of the home page. Try as I might, I could neither update, rename nor replace the file through FTP - the little devils had altered it's file privileges.

I re-uploaded the file into one of the other domains (virtually no changes to the file) and changed all the references to the new location. I knew nothing, of course, at this stage of the reason why. Jason had had surgery earlier that day (Friday) & retired to bed to nurse his wounds - without informing me of what he had done. Double yikes.

Fortunately, whilst changing the calling ‘HREF’s I'd also fixed a mistyping on every page - approx 600 of them. The original HREF was

    “http://modem-help...”
and I changed them all to
    “http://www.modem-help...”
As I said earlier, I still do not know what on earth within this little script could have so crippled the server, but the same script is happily buzzing away at the moment, causing (crossed fingers) no harm.

At the same time during this twin-track story, the curtain-rail is finally ready to be put back into place. Large voids have been stuffed with polyfilla, drilled & battens securely fixed in place & painted. It has all taken an abominable amount of time (you can tell that I live alone) but it is done.

One tiny bit of good to come out of this is that the page date now appears on the page! Apparently JavaScript will not transfer values between IFRAMES unless they are positioned inside the same domain, and since I transferred stats.php into modem-help, Voila!

26 March 2002 Fixing a Newbie MySQL mistake...
  One puzzle to me all this time has been the apparent drop in visitor numbers since removal of the TheCounter.com counter. TheCounter had reported 25,000 visits a day, but my script had a maximum of 20,000 - it was difficult to account for the discrepancy, even allowing for Cache views at Search sites etc. A possible penny dropped at work today.

My programming has had a mind-set of one-view-at-a-time - essentially, a single person working on a single computer, which is my circumstance whilst producing it all. The past couple of weeks has given me the opportunity to swim in the reality of the Server, which of course is a very different environment. At the heart of the updating was a small piece of PHP code:

    1 $q="SELECT Visit,ZID FROM stats WHERE... (the select criteria);
    2 if(list($visit,$zid)=mysql_fetch_row(mysql_query($q))) {
    3  $visit++;
    4  $q="UPDATE stats SET Visit=$visit WHERE ZID=$zid";
    5 } else {
    6  $q="INSERT INTO stats VALUES (NULL,'$page',$yr,$mn,$dy,$domain,1)";
    7 }
    8 $r=mysql_query($q);
It's easily conceivable - especially with the busy pages - that between lines 2 and 8 with one visitor, another visitor will view the page and trigger line 2 before the first has inserted a new value. It's easily fixed by making a small mind-shift, and should be a little faster as well:
    1 $q="SELECT ZID FROM stats WHERE... (the select criteria);
    2 if(list($zid)=mysql_fetch_row(mysql_query($q))) {
    3  $q="UPDATE stats SET Visit=Visit+1 WHERE ZID=$zid";
    4 } else {
    5  $q="INSERT INTO stats VALUES (NULL,'$page',$yr,$mn,$dy,$domain,1)";
    6 }
    7 $r=mysql_query($q);
I'm uploading these changes in a few minutes, so time will show.
01 April 2002 One more reason to hate Microsoft...
  On 15 March above I described putting a page of full statistics in place, so that I & others could see how hits each day & each page had had. At the same time - since every single page was going to have to be changed - I added a ‘Domain’ field to the stats table in the database and used “&domain=1” in the URL to signal a page on the new site. Naturally, what was needed next was a small change to the full-stats page to be able to visually see the difference between those visiting the old (Freeserve) site & those on the hosted site.

3 weeks later it is done. 3 weeks. 3 WEEKS!!! I've learnt rather a lot about CSS, CSS1 & CSS2 in that time - probably more than I wanted to know - and have been spitting tin-tacks at Microsoft's inability to implement correctly any (international) standard that they do not control.

  The idea behind CSS - Cascading Style Sheets - is terrific. Put all of the styling elements (presentation aspects) of a web-page into one place. Then, if the web-author wants to change any style aspect of each page - fonts, colour, layout - make a change in just one place and all the hundreds of pages using the Style Sheet will automatically change accordingly, without having to actually edit any page. It does depend, however, on the Web-Browser producers implementing CSS thoroughly & accurately, and Microsoft's heart doesn't seem to be in it (even the latest version of Internet Explorer has the worst coverage of all modern browsers and each version has a broken implementation of the Box model). Only Opera 5 seems to have got it right.

If you want to read further about CSS, try the following:

  • W3C CSS2 Specification - 12 May 1998
  • CSS test pages + cross-browser compatibility
  • Westciv - an up-to-date CSS1/CSS2 online tutorial
  • CSS Layout Techniques - lots of links
  • BlueRobot Layouts - unfortunately not viewable offline
  • A List Apart - also unfortunately not viewable offline
4 years. I wonder how much longer it will take?
  For what it's worth (nobody seems to read these pages) here's the HTML that worked (produced from a PHP file):
    <DIV CLASS='float'>
      <DIV><IMG SRC='/old/graphics/dot0.gif' WIDTH=33 HEIGHT=141 ALT='2002/3/19' />
      </DIV><DIV><IMG SRC='/old/graphics/dot1.gif' WIDTH=33 HEIGHT=2 ALT='2002/3/19' />
      </DIV>
    </DIV>
..and here is the relevant scrap of CSS file:
    DIV.float
    {
      border: 0;
      margin: 0;
      padding: 0;
      float: left;
      vertical-align: bottom;
    }
The height of each image is proportional to the number of visits on a day. Surrounding each IMG in a <DIV>..</DIV> allows one to sit under the other, and surrounding both in a float-DIV allows this combination to form the graph. After 3 weeks of trying, when I finally saw this working on the screen I sat back in a state of shock for 10 minutes. What I simply cannot fix is that each image hangs down from the top, and I want them to stand up from the baseline. Without the DIVs they do stand up, but with them - no matter what I do - they hang down. If you know the way to fix this, for my sanity's sake, let me know.

The one thing that has given me most fun during this time has been changing the colour of the GIF. The original (dot0.gif above) is a single-pixel of colour #010091, 41 bytes in size. To change the colour required first finding the layout schema of GIF files - I found it here (an astonishing Russian tutorial for Delphi programmers - in English - is here, but unfortunately with a crucial missing page). The only binary editor I had available to me was debug. Once I knew the crucial 3 bytes to change (9,10 & 11), and digging 15 or 20 years back in my memory, and dot1.gif was born. Excellent.

  And finally the curtains...

My Bay Window now has a beautiful set of curtains. The curtain rail turned out to be no longer supported by its manufacturers. To fasten it to the wall required me to cannibalise 2 other rails in the house for their fittings, giving me 9 fasteners (I needed 7). 2 fasteners disintegrated in the process - gasp, just managed it. I prey now that they last a couple of years longer.