get variables?

  • Thread starter Ste (Stefano Russo)
  • Start date
S

Ste (Stefano Russo)

Hi, i would like to know if is possible to recall a variable passed via
get trought a url.

example:

www.terra32.net/perl/ping.pl?url=www.google.it

How can i recall the variable "url" in the script?

Thanks a lot, excuseme for my bad english..

--
|||
(0.0)
|-------------o00----00o-----------------------------|
|Stefano Alberto Russo - Liceo Oberdan - Trieste |
|www.terra32.net - webmaster @ www.acquariofilia.biz |
|----------------------------------------------------|
 
P

Paul Lalli

Hi, i would like to know if is possible to recall a variable passed via
get trought a url.

example:

www.terra32.net/perl/ping.pl?url=www.google.it

How can i recall the variable "url" in the script?

Thanks a lot, excuseme for my bad english..

There are two main ways. One is to manually parse the Query String
environment variable. In your example above, your script would have a
variable
$ENV{'QUERY_STRING'} = 'url=www.google.it';

You could manually parse this variable and set the values you need. This
is generally considered a bad idea by most people. The preferred
alternative is to use the ever popular (and standard) CGI module:

use CGI qw/:standard/;

my $site = param('url');


That will automatically parse the query string and set the variable $site
to whatever value the 'url' GET parameter had.

For more information, read the documentation on CGI.pm:
perldoc CGI

Hope this helps,
Paul Lalli
 
A

A. Sinan Unur

A misspelling which you are invited to correct.

I don't need to. You should not post non-working code.

You snipped the context right out:

Why don't you research, read and find out if "my"
declarations work with Perl 4 installations?


Purl Gurl

The 'my' is not the point there. It is just force of habit that I wrote it.
The question is: Would

$k = keys %in;

not have given the number of keys in the hash in Perl4?
 
S

Ste (Stefano Russo)

Thanks a lot guys!!!

Excuseme if i don't quote, but ill'need to quote all the replies.. :)



--
|||
(0.0)
|-------------o00----00o-----------------------------|
|Stefano Alberto Russo - Liceo Oberdan - Trieste |
|www.terra32.net - webmaster @ www.acquariofilia.biz |
|----------------------------------------------------|
 
J

John Bokma

Tintin said:
#!/usr/bin/perl

add -T
use strict;

use warnings;
use CGI;

my $q = new CGI;

I recommend calling it $cgi instead of $q. It is more than just the
"query", also $cgi is more self-documenting
my $url = $q->param('url');

Be aware that $url can contain anything and can even be undefined.
Check, check, and reject if it is not what you expect. Don't fix it,
reject it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top