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

I'm attempting to write (semi-)intelligent Perl scripts to embed in webpages - the idea being to create elements like context sensitive linking (Previous FAQ and Next FAQ links only in the FAQ directory, for example).

The idea I had was to use the <!--#exec--> SSI directive to embed a Perl script in the page and use $embedpage = $ENV{'PATH_INFO'} to return the name of the page which called the script so that results could be customized by page. Unfortunately this doesn't seem to work in IIS as it returns the name of the script rather than the name of the originating page. I haven't tested this in other server software but switching isn't really an option at this point so I was wondering if anybody knew a way to create the desired effect without switching the whole site over to script instead of static SHTML pages.

Help much appreciated.

Replies are listed 'Best First'.
Re: #exec and $ENV{'PATH_INFO'}
by grep (Monsignor) on Jun 09, 2002 at 23:21 UTC

    Sounds like you are looking for a templating system. It'll work slightly differently.

    You take your static pages turn them into templates, then drive them with a CGI script. You can embed templates inside other templates (much like your the behavior you are looking at SSI for), so you can move your navigation into a footer area

    The possibilties are endless :)

    Some templating systems to look at:

  • Template Toolkit
  • HTML::Template
  • HTML::Mason (only on apache)


  • grep
    Just me, the boy and these two monks, no questions asked.

      The problem I am running into is that the templating system isn't compatable with my current SSI setup. Modifying my current system to fit HTML::Template will take a great deal of thought and effort which I don't want to commit to it because I'm scrapping the current setup for a dynamic one as soon as I get the dynamic system developed.

      This request is for more of a quick fix while I'm building the dynamic site.

      SSI works great for the setup I currently have but it's far too limited for the interactive content that I'm now trying to build into the site so I need to ditch the system anyway.

      Thank you for your input; I'm sure it will come in handy while I'm building the dynamic site.

Re: #exec and $ENV{'PATH_INFO'}
by erikharrison (Deacon) on Jun 09, 2002 at 23:17 UTC

    Last I checked, IIS servers have a broken path info handling. CGI.pm attempts to fix this bug internally, but probably shouldn't be relied upon. As SSI does not allow you to pass in info to the script (at least, not to my knowledge) you might need to just switch to dynamically generating the page entire, using HTML::Template or the like.

    Cheers,
    Erik

    Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

Re: #exec and $ENV{'PATH_INFO'}
by Cody Pendant (Prior) on Jun 10, 2002 at 05:19 UTC
    According to a very quick piece of research, you can use the $ENV{QUERY_STRING} in an executed SSI on Apache to pass information.

    That is, if you have an include in your.server/mypage.html?page=1, the include "knows about" the "page=1".

    This would allow you to pass information in a way, though it's not going to be neat.
    --

    ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;
Re: #exec and $ENV{'PATH_INFO'}
by Joost (Canon) on Jun 10, 2002 at 10:49 UTC
    PATH_INFO does NOT return the URL for the called page, only any extra path data that was appended after the URL for the called page. Example (on Apache):

    You have a page on url http://localhost/test.shtml that includes (with #exec cgi) /script.cgi and you call this with http://localhost/test.shtml/extra/path?param=1 you get the following:

    REQUEST_URI = /test.shtml/extra/path?param=1 PATH_INFO = /extra/path QUERY_STRING = param=1 SCRIPT_NAME = /script.cgi DOCUMENT_URI = /test.shtml/extra/path
    Unfortunately (on Apache), there seems to be no environment variable that shows only the URI of the called shtml page (should be /test.shtml here) if the request contains extra path_info.

    Your best bet would probably be to remove $ENV{PATHINFO} from $ENV{DOCUMENT_URI}.

    Please note that SSI support and implementation varies betweeen different (versions of) webservers, so you probably should test all this yourself by including a test script in a shtml page like this:

    #!/usr/bin/perl print "Content-type: text/plain\n\n"; for (sort keys %ENV) { print "$_ : $ENV{$_}\n"; }
    Also note that using CGI.pm may change the value of certain environment variables. YMMV.
    -- Joost downtime n. The period during which a system is error-free and immune from user input.