Google
  Web alb-net.com   
[Alb-Net home] [AMCC] [KCC] [other mailing lists]

List: Web-design

[web-design] Re: CGI

Dashamir Hoxha e106708 at ceng.metu.edu.tr
Fri Feb 5 04:18:25 EST 1999


            ------------------------------------
            **** Web Design Discussion List ****
            ------------------------------------

Tung,

Me poshte po kopjoj nje leterkembim qe kam patur kohet e fundit.
Mendova se do ishte me interes per antaret e listes [web-design].

Dashamir Hoxha

---------------------------------------------------------------------------

 | > I keep track of all the people that visit my homepage and the sites from
 | > where they were refered to my page. I do this using CGI tricks. If you
 | > know nothing about CGI it would be difficult to explain how I do it,
 | > however, if you know something about it I may tell you the details.
 | 
 | I do know a little about CGI , so please let me know

OK. 

First of all you should name your file <file_name.shtml>
(not <file_name.html> ) for example: "index.shtml"
This should tell your web server to process your page before
sending it to the browser, and to look for any directives,
which are called Server Side Includes (SSI) (from where comes
the extention "shtml"). My server recognizes this extention,
but I am not sure if your server does or if it needs some
configuration to do it; you have to check it out.

Now, what are these directives? 
The one that is used in this case is: 

<!--#exec cmd="/usr/local/bin/perl   path/log_script.cgi"-->

It executes a command and dhe output from the command is inserted
in the HTML and is send to the browser. Concretely, the command
executed in this case is a perl program, "path" is the full or
local path to the program "log_script.cgi". Actually this perl
program produces no output, but it has side effects, which store
some information about the visitor in a log file.

Other SSI's are:
<!--#config errmsg="."-->          (msg displayed if command 
                                           cannot be executed)
<!--#echo var=DATE_LOCAL -->       (display an environment variable)
<!--#config timefmt=" %d %B %Y"--> (set time format for display)
<!--#flastmod file=index.shtml --> (time this file is last modified)
etc.

For more information about Server Side Includes see this page:
  http://www.ceng.metu.edu.tr/~e103686/books/cgi/ch05_01.htm
Also see this page with examples:
  http://www.ceng.metu.edu.tr/~e106708/cgi-bin/test/

What is log_script.cgi? It is enlisted below:
        ^^^^^^^^^^^^^^
#!/usr/local/bin/perl
$time = `/usr/bin/date`;
$remote_host = $ENV{'REMOTE_HOST'};
$remote_addr = $ENV{'REMOTE_ADDR'};
$http_referer = $ENV{'HTTP_REFERER'};
$file = "path/log_file";     ### the file where the logs are kept
open(FILE, ">> $file");
flock(FILE,2);
print FILE<<End_of_Stats;
 
--------------------------------------------------------
 
TIME  :  $time
REMOTE_HOST  :   $remote_host
REMOTE_ADDR  :   $remote_addr
HTTP_REFERER :   $http_referer
 
End_of_Stats
flock(FILE,8);
close(FILE);
exit(0);

It is fairly simple and there is no need for explanations, however, if
there is any dark point, any small thing that you don't understand, you
can ask me.

Lastly, how to load "index.shtml", when all the links that point to your
site are to "index.html"? 
There are several ways to do it; I have used this one: let "index.html"
contain only this line:

<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.shtml">

This will immediately (in 0 secs) redirect the browser to "index.shtml".

Try the things that I have written above, and if there is something that 
does not work, let me know. Be careful with file permissions; expecially
the log file (where you are recording info about visitors) has to have
permissions -rw----rw-, because the program "log_script.cgi" which writes
it, is called from "nobody" (web server), which is "other" for your files,
so you have to grant write permissions for the others. Theoretically, this
makes it possible that everybody can read and write your log file. 
Practically it is impossible, because nobody knows the exact location and
name of this file.

I hope that I have explained it somehow.

----------------------------------------
e106708 at ceng.metu.edu.tr (Dashamir Hoxha)



More information about the Web-design mailing list