home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- # Access the environment variable by name
-
- $script_name = $ENV{'SCRIPT_NAME'};
-
- # Access the counter information indicating whether this script was
- # previously called and how many times.
-
- $path_info = $ENV{'PATH_INFO'};
-
- # Start generating HTML output with the required MIME HTML type.
-
- print "Content-type: text/html\n\n";
-
- # Print HTML header information.
-
- print <<EOH;
- <HTML>
- <HEAD>
- <TITLE>CGI Script How-To: Test Script</TITLE>
- </HEAD>
- <BODY>
- EOH
-
- print "<H1>CGI Script How-to<BR>determine the path of the script being executed</H1>\n";
-
- # Test the path info variable. If it is not set then the script has been
- # called for the first time and will print the appropriate message.
-
- if (!$path_info)
- {
- print "<H2>This is the first time you called this script</H2>\n";
- $count = 1;
- }
-
- # Otherwise the path info variable has been set. In this case we want to
- # increment the counter and say how many times the script has been called.
-
- else
- {
- ($count = $path_info) =~ s!^/!!; # strip off the leading slash
- $count++; # increment the counter
- print "<H2>You have called this script $count times</H2>\n";
- }
-
- # Test the script name variable and use it's value in a link back to itself.
- # Selecting this link will call the script again, but this time with the extra
- # path information indicated by "/$count" which will pass the counter to the
- # script and be stored in the PATH_INFO environment variable.
-
- if ($script_name)
- {
- print qq!<A HREF="$script_name/$count">Cick here to call the script again</A>!;
- }
-
- # If the script name is not defined then print a message.
- # This means the script can't refer back to itself.
-
- else
- {
- # Otherwise we can't link to the script so say it
- printf("I don't know who to call\n");
- }
-
- # Print closing HTML tags.
-
- print "</BODY></HTML>\n";
-
- #
- # end of count.pl
- #
-