mellin has asked for the wisdom of the Perl Monks concerning the following question:

Hey all, i have not so much as Perl related question, but more like CGI-stuff, and i would appreciate any wisdom about this.

I did a short script to parse 'PATH_INFO' variable, this script is used inside .shtml page with SSI. My pages now include links like '/index.shtml/id/335/' and so on. This works fine, if i run the script directly like '/cgi-bin/index.pl/id/335/', but if i try that former '/index.shtml/id/335/', my www-server just shows that index.shtml page, the index.pl script that is being called with SSI does not get the $ENV{'PATH_INFO'} variable.

Why is that so, is there any way to win this? It was a pleasant few hours already doing that perl-code, but now i would like to get this actually finished :)

Code parsing the PATH_INFO is shown below: (some finnish words inside blocks, but main logic should be clear)
#!/usr/bin/perl -w use strict; my $path = $ENV{'PATH_INFO'}; # omit the first '/' sign $path =~ s/^[\/](.*)/$1/; # read string like 'id/995/kk/2004-05/r/5' to @array my @keys = split /\//, $path; my %avain = (); my $i = 0; print "Content-type: text/html \n\n"; # let's go through all the indexes that split made while ($i <= $#keys) { # assign key-value pairs $avain{$keys[$i]} = $keys[($i+1)]; $i = $i+2; } # for debugging purposes while (my ($key, $value) = each (%avain)) { next unless $value; print "<p>$key = $value</p>\n"; }

Replies are listed 'Best First'.
Re: About PATH_INFO and SSI
by Mr. Muskrat (Canon) on Dec 07, 2004 at 02:11 UTC

    I can't really help with the PATH_INFO but I can simplify your code a little. You do not need to create the array if all your going to do is turn around and make a hash out of it.

    my %avain = split /\//, $path; while (my ($key, $value) = each (%avain)) { next unless $value; print "<p>$key = $value</p>\n"; }

Re: About PATH_INFO and SSI
by sgifford (Prior) on Dec 07, 2004 at 06:38 UTC
    This is probably more of an Apache question than a Perl one. From my reading of the documentation, it looks like PATH_INFO should be available. The mod_include documentation says that all standard CGI variables should be available to SSI documents, the mod_cgi documentation says that all variables in the CGI specification will be set, and the CGI Environment Variables part of the spec includes PATH_INFO. So I'm not sure why you're seeing the problem you're seeing, but an Apache guru would probably know.
      I know now why it did not work, 'cause in the middle of the night i just tried one thing, and now the site works.

      It is like this now in the .shtml files:

      <!--#set var="path_info" value="${PATH_INFO}"--> <!--#include virtual="/cgi-bin/index.pl$path_info"-->


      As you see, i had to use SSI-variable to pass that PATH_INFO to the CGI-script. There was no problem with Perl, but what i read at night, Apache will not for some reason pass PATH_INFO and QUERY STRING with GET-method to SSI-included file, but you can get away like this.

      I figured this out with luck, phuuh!