http://www.perlmonks.org?node_id=59352


in reply to Re: CGI queries without '?'
in thread CGI queries without '?'

Indeed it does.

This being the case, can CGI.pm correctly handle such information gathering, or is it up to the programmer to risk it all and handle the variable on their own? ... (I'm not saying I condone this practice)

Replies are listed 'Best First'.
(dkubb) Re: (3) CGI queries without '?'
by dkubb (Deacon) on Feb 19, 2001 at 12:10 UTC

    IMHO it is better to use CGI.pm to access the Path Info string than to access $ENV{PATH_INFO} directly, with the CGI::path_info method. There's alot of good reasons to do this, here are some of mine:

    • CGI deals with implementation issues. If the structure of the %ENV hash ever changed, my code wouldn't break, assuming the module is kept up to date.
    • CGI::path_info corrects common problems in certain web servers, providing a more portable solution than direct access to $ENV{PATH_INFO}.
    • You get documentation of the CGI::path_info method to explain what it does. This means less documentation for me, I like that =) It's much more difficult to find docs explaining the %ENV hash well.
    • It just looks prettier.

    In general, anytime I need to access the %ENV hash, I try to look in CGI.pm's docs for a method to get at the data I want.

      The best reason of all to use CGI.pm's functions to access the ENV hash is that if your URL string happens to contain an unusual character, say a percent sign or a caret, then directly parsing the environmental variables will usually break your program. CGI.pm, on the other hand, will seamlessly preserve the unusual character and return it the same way it went in. MS-DOS directory names, for instance, can contain percent signs, so this possibility is not merely theoretical.

      Also, I suspect that a clever hacker may be able to engage in misdeeds by submitting unusual input after the '?' or '/'. CGI.pm, which is written by a really brilliant programmer named Lincoln D. Stein, probably screens for at least some types of miscreant CGI input.

      For those who are as clueless concerning CGI.pm as I was a few months ago, it is built into current versions of Perl, so there is no need to download or install it.

      Hail Lincoln Stein! I do not like to engage in hero worship, because we can all be heroic programmers someday, but this piece of open source work by Mr. Stein is really superb.

Re: Re: CGI queries without '?'
by eg (Friar) on Feb 19, 2001 at 11:56 UTC

    ??? It has nothing to do with CGI.pm. The pathinfo will be in the %ENV hash.

    my $pathinfo = $ENV{PATH_INFO} || '';

    update: Good point, dkubb. Thanks. I didn't realize I could get the PATH_INFO from CGI itself.