CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
empty ENV variables

 



seriousfun
Novice

May 29, 2001, 2:49 AM

Post #1 of 6 (825 views)
empty ENV variables Can't Post

I am endeavouring to isolate the url that was used to reach my script. I have tried using the $ENV{'REQUEST_URI'} but it appears to be empty.
The line of code is
print "env var = ",$ENV{'REQUEST_URI'},"
the print out from the code is

env var =

what have I done wrong??



widexl
Novice

May 29, 2001, 3:25 AM

Post #2 of 6 (821 views)
Re: empty ENV variables [In reply to] Can't Post

Try this

print "env var = $ENV{'REQUEST_URI'}";




seriousfun
Novice

May 29, 2001, 3:38 AM

Post #3 of 6 (819 views)
Re: empty ENV variables [In reply to] Can't Post

Tried that but the variable is still empty. Am I supposed do something else before referencing the variable?



mhx
Enthusiast / Moderator

May 29, 2001, 4:34 AM

Post #4 of 6 (814 views)
Re: empty ENV variables [In reply to] Can't Post

Hi,

another 'try this', it should print a list of all your environment variables. If the one you're searching is not in the list, there must be another problem.

Code
print "\$ENV{$_} = $ENV{$_}\n" foreach sort keys %ENV;

Hope it helps,

-- Marcus



seriousfun
Novice

May 29, 2001, 5:07 AM

Post #5 of 6 (811 views)
Re: empty ENV variables [In reply to] Can't Post

I have now run this small program

#!/usr/bin/perl

print "Content-type: text/html\n\n";

%EnvVarList=
(
'AUTH_TYPE', 'Servers\'s authentication method is: ',
'REMOTE_ADDR', 'Client IP address as: ',
'REQUEST_URI', 'Requested url is : '
);
print "<HR>","\n";

while (($EnvironVar, $Desc) = each (%EnvVarList))
{
print $EnvironVar, ": ", $Desc, $ENV{$EnvironVar}, "<BR>", "\n";
}


and the only ENV variable holding a value is the remote address. Why are the other values blank and how can I access them????



mhx
Enthusiast / Moderator

May 29, 2001, 5:47 AM

Post #6 of 6 (809 views)
Re: empty ENV variables [In reply to] Can't Post

Hi,

have you tried to run my script? If not: RUN IT!
Not every HTTP server must set every possible environment variable. My server doesn't set AUTH_TYPE, for example. But besides REQUEST_URI, there are other variables in my environment that contain nearly the same information. When running my script, you will get a list of all of them, and perhaps you'll find something else you may want to use.
Besides, I don't think your requested ENV variables are empty, I think they don't even exist. You can verify this by either running my script (did I mention you should run it?) or by explicitly checking if the key exists in the hash table using the exists function.
FYI, here's a list of my server's variables, printed with a script similar to mine:

Code
QUERY_STRING =  
HTTP_ACCEPT_LANGUAGE = en-us
SERVER_PROTOCOL = HTTP/1.0
REMOTE_PORT = 4607
HTTP_ACCEPT = application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
HTTP_USER_AGENT = Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)
GATEWAY_INTERFACE = CGI/1.1
HTTP_HOST = mhx.netfirms.com
SERVER_SOFTWARE = Apache/1.3.9 (Unix)
SERVER_ADMIN = Your Webmaster
SCRIPT_URI = http://mhx.netfirms.com/cgi/printenv
REMOTE_ADDR = 156.153.255.114
SCRIPT_NAME = /cgi/printenv
SCRIPT_URL = /cgi/printenv
SERVER_NAME = mhx.netfirms.com
DOCUMENT_ROOT = /d01/sec/s24/a0002e0t
REQUEST_URI = /cgi/printenv
REQUEST_METHOD = GET
SCRIPT_FILENAME = /cgi/printenv
PATH = /usr/local/bin:/usr/bin:/bin
HTTP_CACHE_CONTROL = max-stale=0
SERVER_PORT = 80

-- Marcus


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives