Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI Environment Variables

Status
Not open for further replies.

wsexton

Technical User
Dec 4, 2001
49
0
0
US
I'm trying to display environment variables in my browser (IE):

Here's the html:

<head>
<title>variable test</title>
</head>
<body bgcolor=white>
<center>
<a href=cgi-bin/env.pl>Environment Variables Example</a>
</center>
</body>

Here's the perl:

#!/usr/bin/perl

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

print "<HEAD><TITLE>Environment VARIABLES</TITLE></HEAD><br>";
print "<BODY><H1>Some Environment variables</H1><br>";
print "<br>";
print "<HR><PRE>\n";
print "Your current IP address is: $ENV{'REMOTE_ADDR'}<BR>\n";
print "Your Browser is: $ENV{'HTTP_USER_AGENT'}<BR>\n";
print "The page you were just on is: $ENV{'HTTP_REFERER'}<BR>\n";
print "The server sending you this page is: $ENV{'SERVER_NAME'}<BR>\n";
print "</PRE></BODY>\n";

Here's what is displayed in my browser:

#!/usr/bin/perl print "Content-type: text/html\n\n"; print "
"; print "
Some Environment variables

"; print "
"; print "
--------------------------------------------------------------------------------

\n";
print "Your current IP address is: $ENV{'REMOTE_ADDR'}\n";
print "Your Browser is: $ENV{'HTTP_USER_AGENT'}\n";
print "The page you were just on is: $ENV{'HTTP_REFERER'}\n";
print "The server sending you this page is: $ENV{'SERVER_NAME'}\n";
print "
\n";

I'm not sure why it's doing this. Can anyone help? Thanks.
 
Code:
#!/usr/bin/perl

use warnings;
use strict;
use CGI qw/:standard/;
print header, start_html();

foreach(keys %ENV)
{
   print "$_<br>";
}
print end_html;
 
When I run that I get a file download message box. I select open, a command box flashes, then it doesn't do anything. I'm running this on my PC using XP. I have IIS installed and I believe I've correctly set up CGI. I also have perl installed and I've set up IIS to use perl to execute both .cgi and .pl files. Any ideas? Is it an IIS problem?
 
Perl isn't properly configured for IIS. Take a look at faq219-3559 to get a pretty concise walkthrough of how to set up CGI and Perl for IIS.

- Rieekan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top