Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies





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

5+ Year Member

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!
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 {
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>";


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

WebmasterWorld Senior Member 10+ Year Member

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!


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

5+ Year Member

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


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

5+ Year Member

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:



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

5+ Year Member

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