Last updated on April 19th, 2022 at 10:43 am

There are many methods in perl on how to send HTTP GET request and grab it on the targeted web page. Different modules are available which will allow us to get the requested variables easily. Here i am not going use any modules. Just a simple straight forward script for displaying or saving the HTTP GET request variable which was submitted from a HTML form.

If you are using modules then LWP::UserAgent is the best one. Check this tutorial on how to install perl modules easily in Linux.(without using CPAN)

Here is the HTML form script

<form name="server" action="" method="GET">
Enter Your Name <input type="text" name="myname">
<input type="submit" value="Sumit">

This will be the perl script that grabs the name that you have entered on the form will look like this

#!/usr/local/bin/perl -w
use CGI qw(:standard);
print header;
my $buffer;
my $pair;
my $name;
my $value;
my $FORM;
my %FORM;
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
    if ($ENV{'REQUEST_METHOD'} eq "GET")
        $buffer = $ENV{'QUERY_STRING'};
    # Split information into name/value pairs
    my @pairs = split(/=/, $buffer);
my $name= $pairs[1];
print "My Name Is $name";

Please make sure you have changed the path of the interpreter / Shebang (/usr/local/bin/perl) in the script above.

Sample Output (Not using the HTML form and directly passing the parameter in the script

# curl localhost/cgi-bin/
My Name Is thomas

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *