Solved

how to use get method?

Posted on 1998-08-24
21
165 Views
Last Modified: 2010-03-04
Well I'm kinda new at this perl stuff so please bear with me on this.

I have writen the following script:

#!/usr/local/bin/perl



# Receive info from Posting
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);
      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      $value =~ s/<!--(.|\n)*-->//g;
      $value =~ s/<([^>]|\n)*>//g;
      $INPUT{$name} = $value;
}


# Print Follow Up HTML
sub follow_up {

print ("Content-Type: text/html\n\n");
print ("<html><head><title>TEST</title></head>\n");
print ("$INPUT{'name'}.<---------\n");
print ("</body></html>\n");

exit;

}

I would like this script to work wiht the get method instead or as well as the post method. Is this Possible? How do I do it? Could any one re write this for me?

Thanks in advance, david
0
Comment
Question by:fusion123
  • 12
  • 8
21 Comments
 
LVL 4

Expert Comment

by:martinag
Comment Utility
Replace this:
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
with this:
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
  $buffer = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
  $buffer = "";
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {
  # Invalid METHOD.
}

Martin
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
At the else statement you will mostly want to print some error message and then exit.

Martin
0
 

Author Comment

by:fusion123
Comment Utility
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 

Author Comment

by:fusion123
Comment Utility
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
In Perl, else if is written as elsif.
Strange, but...

You should replace only that line.

When running, do you get any error messages?

Martin
0
 

Author Comment

by:fusion123
Comment Utility
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 

Author Comment

by:fusion123
Comment Utility
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 

Author Comment

by:fusion123
Comment Utility
ya I get a 500 error
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
Here is your new code:

#!/usr/local/bin/perl

# Receive info from Posting
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
  $buffer = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
  $buffer = "";
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {
  # Invalid METHOD.
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$value =~ s/<([^>]|\n)*>//g;
$INPUT{$name} = $value;
}

# Print Follow Up HTML
sub follow_up {
print ("Content-Type: text/html\n\n");
print ("<html><head><title>TEST</title></head>\n");
print ("$INPUT{'name'}.<---------\n");
print ("</body></html>\n");

exit;
}

BTW, I guess this is not your entire script.
You never call follow_up.

Martin
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
It works fine for me...

Martin
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:fusion123
Comment Utility
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 

Author Comment

by:fusion123
Comment Utility
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
Are you posting that comment all the time?
There's something strange going on around here...

Martin
0
 

Author Comment

by:fusion123
Comment Utility
OK well like I said perl is not my strenght. I have tried it several different ways including just copying the code you placed online for me and still no luck?

Hmmmmm

you can take a peek if you like

http://www.fusion.ca/cgi-bin/test.cgi
thanks I'm sure really what else to do?

You say it works for you eh?
0
 

Author Comment

by:fusion123
Comment Utility
OK well like I said perl is not my strenght. I have tried it several different ways including just copying the code you placed online for me and still no luck?

Hmmmmm

you can take a peek if you like

http://www.fusion.ca/cgi-bin/test.cgi
thanks I'm sure really what else to do?

You say it works for you eh?
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
#!/usr/local/bin/perl
#does this script work?
print ("Content-Type: text/html\n\n");
print ("<html><head><title>TEST</title></head>\n");
print ("<body>---------\n");
print ("</body></html>\n");
0
 

Author Comment

by:fusion123
Comment Utility
Yes it does work on it's own.
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
You said you got a 500 error...Where does it happen and what does the 500 mean?
Use -w.
Give us the line where the error occures and some of the lines before it.

Martin
0
 

Author Comment

by:fusion123
Comment Utility
TO  martinag:

hey thanks for your help I figured it out with your help there. <and every one elses thanks> I would like to give you the 100 pts so go a head and lock the question.
0
 
LVL 4

Accepted Solution

by:
martinag earned 100 total points
Comment Utility
Thank you!

Just curious...what was not working?

Martin
0
 

Author Comment

by:fusion123
Comment Utility
Thanxs again
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now