From e106708 at ceng.metu.edu.tr Fri Feb 5 04:18:25 1999 From: e106708 at ceng.metu.edu.tr (Dashamir Hoxha) Date: Fri, 5 Feb 1999 11:18:25 +0200 (EET) Subject: [web-design] Re: CGI Message-ID: <199902050918.LAA11914@davul.ceng.metu.edu.tr> ------------------------------------ **** 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 (not ) 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: 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: (msg displayed if command cannot be executed) (display an environment variable) (set time format for display) (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< 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)