Query string help!

Justin S's picture

They have: 2,076 posts

Joined: Jun 1999

Ok, here's my question... I want to make a script that once I goto a URL (IE: [url=http://www.some.com/cgi-bin/some.cgi?action=post)]http://www.some.com/cgi-bin/some.cgi?action=post)[/url] it will put the action type (in this case it's 'post') into a varible. Anyone have a snipped of code? Thanks...

------------------
Critiquing over 1000 sites on the Internet today...

They have: 14 posts

Joined: May 2000

Hi justin.

Its real easy using the CGI module. Take a look. It takes care of QUERY_STRING/CONTENT_LENGTH.

code:

use CGI qw/:standard/;
$action = param('action');
[/code]

Hope that helps,

Arpith



------------------
Arpith.com 

They have: 568 posts

Joined: Nov 1999

Ok, I think I understand your problem so see if this will do it for you.

code:

$string = $ENV{'QUERY_STRING'};
$string =~ m/action=(.+)/sogi;
$action = 1;
print $action;
[/code] 
Justin S's picture

They have: 2,076 posts

Joined: Jun 1999

Hmm, it doesn't seem to work Orpheus. Here's the full script. Please tell me whats wrong...

code:

#!/usr/bin/perl

#######################################################################
## POST.CGI
## Justin Stayton
## Copyright (c) 2000 Justin Stayton
#######################################################################

#######################################################################
## VARIABLES
#######################################################################

#######################################################################
## CODE
#######################################################################

## PARSE URL DATA
$string = $ENV{'QUERY_STRING'};
$string =~ m/action=(.+)/sogi;
$action = 1;

## USE THE PARSED DATA AND SHOW INFORMATION
if($action eq "showpost") { &showpost; }
elsif($action eq "showreply") { &showreply; }
elsif($action eq "savepost") { &savepost; }
elsif($action eq "savereply") { &savereply; }
else { &showerror; }

## SHOW POST PAGE
sub showpost {
   print "this is a test 1";
   exit;
}

## SHOW REPLY PAGE
sub showreply {
   print "this is a test 2";
   exit;
}

## SAVE POST CODE
sub savepost {
   print "this is a test 3";
   exit;
}

## SAVE REPLY CODE
sub savereply {
   print "this is a test 4";
   exit;
}

## SHOW ERROR PAGE
sub showerror {
   print "this is a test 5";
   exit;
}

#######################################################################
## END OF POST.CGI
#######################################################################
[/code]

------------------
Critiquing over 1000 sites on the Internet today... 

They have: 122 posts

Joined: Jun 2000

Because

code:

######################################################################### PARSE URL DATA
$string = $ENV{'QUERY_STRING'};
$string =~ m/action=(.+)/sogi;
$action = 1;[/code] sets $action equal to 1, not to the action, and you're checking $action later for 'showpost' and such.

[This message has been edited by roBofh (edited 05 June 2000).] 

Rob Radez
OSInvestor.com

They have: 568 posts

Joined: Nov 1999

erp... major typo

replace 1 with $1

THAT will work. promise

Justin S's picture

They have: 2,076 posts

Joined: Jun 1999

Aha! Thanks alot everyone...

ORPHEUS: did you get my e-mail? what's your ICQ or AIM address?

------------------
Critiquing over 1000 sites on the Internet today...

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.