Coding Domain

Perl Modules: CGI::Location


Downloads
Perl Modules
Name
CGI::Location - CGI Location Detection

Synopsis
use CGI::Location;

print "Current URL is: $THIS_URL";
print "Website home page is: $THIS_SITE/index.html";

DESCRIPTION
This module makes any CGI program capable of detecting their own location, so no variables needs to be set anymore!

Variables added to the main package
$THIS_PATH
The current path of the script based on the $0 variable, eg /httpd/www/you/cgi-bin

$THIS_UPPATH
The higher path where the current script is found, eg: /httpd/www/you

$THIS_URL
The current URL of the script, eg: http://www.you.com/cgi-bin/script.cgi

$THIS_SITE
The current website the script is located, eg: http://www.you.com The http:// prefix is assumed, not detected!

$THIS_NOPR_SITE
Same as previous item, but without the http:// prefix.

$SERVER_NAME
The internet name of the computer, eg: www.you.com

$PORT
The port of the webserver, undef for default (is 80) and any other value when a different port is being used.

$THIS_URLPATH
The path from the current URL, eq: /cgi-bin

$THIS_URLUPPATH
The higher path from the current URL, eg: a empty string if $THIS_URLPATH has the value /cgi-bin

$THIS_SCRIPT
The path+filename of the current URL, eg: /cgi-bin/script.cgi

$S
The path separator used to separate paths at the webserver's filesystem.

$THIS_OS
A extra feature. This is the OS name. Unlike $^O, this string is less detailed, and easier to use in a string test.

$IIS, $IISVER
True if the current webserver used is the 'Internet Information Server' is used. This variable can be useful to fix problems caused by some assumptions that server makes. However, it appears that IIS/5.1 has some fixes at this point. That's why this module also provides the $IISVER variable.

Exported Functions and Variabels
ParseFilePath(Filename, [PathSeparator])
Extracts the path from a filename, using a specified path separator, or the default value.

@CGI::Location::VARNAMES
Contains all names of the variables added to the main package.

Internet Information Server Issues

The Internet Information Server from Microsoft has some nasty bugs in it. Therefore the $IIS and $IISVER variables are available. Some of the errors caused in the IIS server are fixed in the 5.1 release. In previous releases, the current-directory pointed to the www-root directory. This resulted in difficult problems concerning require/open/use lines depending on the current directory variable. After loading this module, your @INC, %INC and 'current directory' will be changed to make the rest of the script work exactly the same for each server. so all your require and open lines in your scripts will then work as they should be. Include files that were expected at the www-root directory (because of that bug) will still work correctly, since this path is also added to the @INC array.

BUGS
This module relies very much on the Environment variabels and a bit on the $0, used by the webserver software.

The protocol is assumed to be http:// but a no-protocol variable is avaible aswell.

The path separator used in %INC, is assumed to be a slash (/).

Author
Copyright (c) 2001, Diederik van der Boor - All Rights Reserved