On Tuesday 19 March 2002 9:09 am, tjones wrote:
I'm writing a simple cgi counter for my school's website. I need some way of getting the name of the current page via the cgi. the closest i've got so far is the enviroment variable HTTP_REFERRER, but tells me the previous html page and not the current one :-(
TIA
Surely, the referrer is what you want. I'm asuming you want to add a page couter to any page you want. You will therefore add a link to that page pointing at your counter. In this way, the HTTP_REFERRER contains the name of the page that is calling your counter. If on the other hand, you're creating a counter module that will sit inside other CGI's then you need to look at the SCRIPT_NAME field as this contains the name of the script being run (e.g. http://www.ringways.co.uk/cgi-bin/envprint would have /cgi-bin/envprint in SCRIPT_NAME. I've included envprint below as it's a priceless little perl script for displaying all available environment variables.
Tim Jones ICT Techniction Manor High School
__ENVPRINT__
#!/usr/bin/perl
#
# CGI script to print out the relevant environment variables.
# It's just one big print statement, but note the use of the
# associative %ENV array to access the environment variables.
#
print <