in reply to get parameter from html page

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^2: get parameter from html page
by friedo (Prior) on Dec 22, 2006 at 06:11 UTC

    Do not do this!

    The proper, secure, standards-compliant way to retrieve HTML form parameters is to use the CGI module.

    As for the OP, try the following:

    • Turn on strict and warnings.
    • Fix your broken HTML
    • You need to print a CGI header before sending any other data.
    • If all else fails, check your error logs.

Re^2: get parameter from html page
by chromatic (Archbishop) on Dec 22, 2006 at 08:53 UTC

    Here are a handful of the flaws of this code:

    print "Content-type:text/html\n\n";

    \n\n is the incorrect header terminator. \r\n\r\n is usually closer, but I admit that I don't know the proper set of characters off-hand, because I never send them directly.

    if ($ENV{'REQUEST_METHOD'} eq "GET") {

    Not technically incorrect, but there are HTTP verbs other than GET and POST.

    read(STDIN, $request,$ENV{'CONTENT_LENGTH'})

    There's no sanitizing of the CONTENT_LENGTH variable, leaving this script wide open to a denial of service attack by either blocking and waiting for more input than is available, or eating up all of the memory if someone sends a long stream of garbage. (I'm not positive that everything is vulnerable to the blocking attack.)

    @parameter_list = split(/&/,$request);

    ; is also a key/value pair separator in HTTP.

    $name =~ s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/ge;

    I believe there's a flaw in here related to invalid hex values, but I can't prove it right now.

    $passed{$name} .= ":$value";

    This makes no sense. I've used the colon in both keys and values before. An earlier version of similar code at least used null bytes; that seemed somewhat more sane.

      print "Content-type:text/html\n\n";
      \n\n is the incorrect header terminator. \r\n\r\n is usually closer, but I admit that I don't know the proper set of characters off-hand, because I never send them directly.
      It doesn't matter. You are not sending them directly to the browser. There's still a webserver between the CGI scipt and the browser, and this one fixes up the output from the CGI script, it even changes/adds headers.

      Bare newlines are just fine.

        There's still a webserver between the CGI scipt and the browser, and this one fixes up the output from the CGI script, it even changes/adds headers.

        I don't take much comfort in that. Perhaps you could mention said web server and its particular configuration and the cases in which it will not mangle the headers (as I can think of at least one configuration option to prevent Apache httpd from doing so).

        All, Thanks for the heads up, as I said I am new to Perl, and the code I posted was the best solution I got from a google search on how to retrieve a query string. Unfortunately the web project I was planning to start in Perl sorta got indefinately delayed so no harm done. This has however given me time to learn. Can someone post a good tutorial for me on how to use perl to make webpages? In particular how to integrate perl code in HTML so I can design a layout in HTML and just have dynamically printed lists and article etc. Thanks again