homepage Welcome to WebmasterWorld Guest from 54.204.94.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Query_string
$ENV{"QUERY_STRING"}
emon




msg:434367
 12:04 pm on Mar 12, 2006 (gmt 0)

Help, I wish to use many link in my page with [IF] function, I can't because don't function 2 QUERY_STRING in my page!
Ex.
print "<a href=index.cgi>Home</a>
<br><a href=index.cgi?links>links</a>
<br><a href=index.cgi?about>About Us</a>";

$menu = $ENV{'QUERY_STRING'};
if ($menu eq "about") {&displayAbout;}
elsif ($menu eq "links") {&displayLinks;}
else {&displayHome;}

sub displayHome {
$h = $ENV{'QUERY_STRING'};
if ($h eq "de") {&de;}
elsif ($h eq "fr") {&fr;}
else {&en; print $home;}
print "<a href=$ENV{'SCRIPT_NAME'}>en</a>
<a href=$ENV{'SCRIPT_NAME'}?de>de</a>
<a href=$ENV{'SCRIPT_NAME'}?fr>fr</a>";
}

 

rainborick




msg:434368
 4:26 pm on Mar 12, 2006 (gmt 0)

The environment variable $ENV{'QUERY_STRING'} contains all of the HTTP request that comes after the "?". In order to extract the information from the query string, you need to parse it with something like: (untested code)

@pairs = split("\&",$ENV{'QUERY_STRING'});
foreach $command (@pairs) {
($parameterName,$value) = split("=",$command);
if ($parameterName eq 'menu') { $menu = $value; }
}

You might also want to learn about using the CPAN module CGI.pm which simplifies common CGI interface issues. Good luck!

emon




msg:434369
 4:19 pm on Mar 13, 2006 (gmt 0)

Thanks rainborick!... but don't function!
Please, help me, write an example with: change lang and menu link in only one page.

perl_diver




msg:434370
 7:18 pm on Mar 13, 2006 (gmt 0)

hi emon,

The way you have your querystrings could work:

<a href=index.cgi?links>

you don't have to have a name/value pair, a single word can work. But your links would be better if they were written as name/value pairs:

<a href=index.cgi?name=value&name=value>

this way you can send multiple commands to your script and use the CGI module to process the commands, or send only one name/value pair it that's what you want to do. Say your links look like this:

<a href=index.cgi?com=about&lan=de>
<a href=index.cgi?com=links&lan=fr>


use strict;
use CGI qw/:standard/;

my $menu = param('com');
my $lan = param('lan');

if ($menu eq 'about') {&displayAbout;}
elsif ($menu eq 'links') {&displayLinks;}
else {&displayHome;}

sub displayHome {
if ($lan eq 'de') {&de;}
elsif ($lan eq 'fr') {&fr;}
else {&en; print $home;}
}


Read the CGI documentation for more indepth explanations:

[perldoc.perl.org...]

emon




msg:434371
 10:46 am on Mar 16, 2006 (gmt 0)

Thanks perl_diver, I have able to make this code! Is great!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved