separator

Take a quiz or make one of your own
Tutorial 3 - Web Hit Counter Using an Image Tag
Installation:
Part I: Server side installation:
  1. ftp article03.cgi to your cgi-bin/thecgibin directory
  2. on telnet change directories to cgi-bin/thecgibin and enter the command 'perl -wc article03.cgi'.
    • you should get the response 'article03.cgi syntax ok'


  3. now that the program's on your server and compiles cleanly, you need to set up the data file. use the 'data' subdirectory of thecgibin.
    • create a new file on your text editor and type the number 0 on it and save the file as article03.dat
    • now ftp article03.dat into cgi-bin/thecgibin/data
    • on telnet say 'perl -wT article03.cgi'
    • here's what I got back on my server...
      cannot open image file: No such file or directory at article03.cgi line 36.
    • now look at the contents of cgi-bin/thecgibin/data/article03.dat. if you ran the program once it should equal '1', because even though it died on line 36 when it couldn't open the image file, it did so after it updated the count file


Preparing the Image File on Your Server :
So now you need an image file for &prtpx to output, and it's going to be named a.gif on the same directory as the program. Point your web browser to http://www.thecgibin.com/download/ and right click on the file 'a.exe'. Now select 'Save Link As' (Netscape) or 'Save Target As' (Explorer). Your browser will start to download and ask you where to put it and what to name it. Put it in the same directory as your article03.cgi program, and name it a.gif. If it renders it instead you'll get a blank screen because after all, it is a 1 pixel transparent gif. In that case, hit the back button (or press alt+<-) to get back to the main download directory, and try again.
Now that you've got the image file downloaded from my server, you can FTP it to your server. Be sure to put it in cgi-bin/thecgibin/, the same directory you put the article03.cgi program into. You'll have to make sure that the file transfer is done using binary mode, as opposed to ascii mode which is what we've used for all our other uploads so far.
Part II - Installation on the Web:
First of all, let's get those pesky permissions done right. You'll need to specify the following chmod's for your files.

article03.cgi 755
article03.dat 666
a.gif 644


Now we have the program, the data file that the program is updating, and the gif image file that the program is reading and outputting to our web page. We're just missing... you guessed it. The web page code. It'll be very similar to the one we used for tutorial 2, with a couple of slight differences.
Here it is :

<html>
<head><title>Hello Out There</title></head>
<body bgcolor="#FFFFFF">

<img src="article03.cgi" width="1" height="1" alt="">

<h1>Hello Out There (Version Two)</h1>

</body>
</html>
Installing your Webpage:
  1. in your text editor copy the html code above into a file on your local computer and call it article03.html, we don't need to use the shtml extension anymore because we're not using a server side include, just a plain old HTML image tag
  2. ftp article03.html to your cgi-bin/thecgibin directory
  3. now get on a browser window and type in the url http://www.mysitename/cgi-bin/thecgibin/article03.html/
  4. now go to ftp and look at the data/article03.dat file if it didn't change double check the chmod's and try again
  5. reload the page a few times and verify that the article03.dat file has changed accordingly, we've used the pragma: no-cache instruction so that image should reload each time we refresh the page, and the count file should be updated with each reload
  6. and of course the page should say "Hello Out There (Version Two)" in great big letters

separator

© thecgibin.com