Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get current URL from CGI-Perl program? - Apache

1,660 views
Skip to first unread message

andré caron

unread,
May 29, 2003, 6:51:35 PM5/29/03
to
Hi,

With a CGI-Perl program, is it possible to get the URL that the user sees?
I found the module Apache::URI but I'm still unable to get the current URL.
How can I get the URL?

OS: Red Hat 8, intel
Perl: 5.8.0
Apache 2

Many thanks,

André
Mirabel, Canada


John Malia

unread,
May 29, 2003, 7:28:25 PM5/29/03
to
Do these help?

$ENV{'HTTP_REFERER'}
$ENV{'SCRIPT_NAME'}


John 88{Q

"andré caron" <anal...@videotron.ca> wrote in message
news:_9wBa.3814$xG4....@weber.videotron.net...

Alan J. Flavell

unread,
May 29, 2003, 7:29:36 PM5/29/03
to
On Thu, May 29, andré caron had posted a copy separately to
comp.lang.perl.modules that I'd already taken time and effort to
answer on .misc:

> Hi,
>
> With a CGI-Perl program, is it possible to get the URL that the user sees?

Don't multipost.

[x-posted and f'ups set]

echoin...@gmail.com

unread,
Feb 4, 2014, 1:28:20 AM2/4/14
to
I wanted to quickly input here. I've been using this, especially where I have apps that run on both http:// and https://

In my case where I use OOP it's usually a subroutine in the main package, but this works just as well, calling the $page_url variable.

Some smart concatenation, no additional modules, strictly native...

<code>
my $page_url = 'http';
if ($ENV{HTTPS} = "on") {
$page_url .= "s";
}
$page_url .= "://";
if ($ENV{SERVER_PORT} != "80") {
$page_url .= $ENV{SERVER_NAME}.":".$ENVSERVER_PORT}.$ENV{REQUEST_URI};
} else {
$page_url .= $ENV{SERVER_NAME}.$ENV{REQUEST_URI};
}
</code>

what do you think?

Uri Guttman

unread,
Feb 5, 2014, 2:23:15 PM2/5/14
to
>>>>> "e" == echoingwalls <echoin...@gmail.com> writes:

e> my $page_url = 'http';
e> if ($ENV{HTTPS} = "on") {

that is wrong on 2 levels. == is comparison and you assigned there. that
will always be true. and eq is used for string compares, not ==.

e> $page_url .= "s";
e> }
e> $page_url .= "://";
e> if ($ENV{SERVER_PORT} != "80") {
e> $page_url .= $ENV{SERVER_NAME}.":".$ENVSERVER_PORT}.$ENV{REQUEST_URI};

missing { on server port.

e> } else {
e> $page_url .= $ENV{SERVER_NAME}.$ENV{REQUEST_URI};
e> }

no need for the option on port as :80 is perfectly valid to use.

and "" is better coding than . ops.

$page_url .= "$ENV{SERVER_NAME}:$ENV{SERVER_PORT}$ENV{REQUEST_URI}";

uri

0 new messages