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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi-bin

Status
Not open for further replies.

flacko21stpl

Programmer
Dec 31, 2005
7
0
0
im using windows xp pro iis and i wanted to know how to use perl script. at this point i made 2 code. the first one is:
#!c:\perl\bin

print "hello world"
i save it as hello.pl in the dir of c:\perl\site\lib\so what i do is in the command line change the path like this: cd c:\perl\site\lib\www
so now im in the dir then i enter perl hello.pl
and i get back a reply back hello.
but when i made the second code:
#!c:\perl\bin

print "content-type text/html\n\n";
print "<html>";
print "<head>";
print "<title>my first perl</title>";
print "</head>";
print "<body>";
print "your ip adress is: $env{remote_host}";
print "</body>";
print "</html>";
i save this as myip.pl i get a reply back as <html><head>
<title>my first perl</title></head><body>your ip address is:</body></html>
and thats all what do i need to do to see my ip in my browser and where do i save the code, im i saving it in the right place.
 
I don't use Windoze but I assume you're using IIS.
There should be a cgi-bin folder somewhere that you can put this script in. Try searching your filesystem for cgi-bin.
I do not know how you configure IIS to run Perl as CGI but I'm sure GOOGLE would know.


Trojan.
 
what about linux redhat9.0 im doing the same on both os same code but a lil dif, in first line its:#!/usr/bin/perl
i get in linux an error 500 i put my code in the cgi-bin dir,
 
Have you tried a "perl -c" on the code to ensure it compiles correctly?


Trojan.
 
$env{remote_host}

should be

$ENV{'REMOTE_HOST'}

--Paul

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
this is how i compiles perl. in the command line a enter perl hello.pl
 
where can i get http server and how can i check to see if its install already.
 
You can check the FAQ's here and in the perl forum missbarbell has written some informative FAQ's on the subject of setting up IIS for perl

HTH
--Paul

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I use Windows XP Pro SP 2 flacko21stpl and the first sign of IIS being installed is a directory structure similar to C:\Inetpub\ on your harddrive. In order to use CGI scripting in perl you just need to download and install ActiveState's ActivePerl and the installer will create mappings for IIS for you as long as IIS is installed in the first place. Then just add a folder called cgi-bin somewhere it doesn't matter where and put your scripts in there so the structure now looks like: C:\Inetpub\ To execute the perl script point your browser to
Also when I first started to use perl I made the grave mistake in assuming I could use the extension .cgi in the cgi-bin, but this is not true. ActivePerl does not create such a mapping and you will have to do it manually in the Microsoft Management Console. It's not that difficult really, just copy the mapping for .pl and use the extension .cgi. You could do the same for .plx and .cgix. May I also add that IIS also has a setting for default file extensions and you could add index.cgi to this list and so you would only need to point your browser to and IIS will load index.cgi for you.

To install IIS select Start->Control Panel->Add or Remove Programs->Add/Remove Windows Components and scroll down until you see Internet Information Services. If you're going to install Visual Studio .NET 2003/2005 then it's a good idea to also install FrontPage 2000 Extensions and for good measure the FTP server as well. This will create a directory structure such as C:\Inetpub\ftproot\.

I hope this has been helpful to you. Anymore questions just yell.
 
I've never seen $ENV{'REMOTE_HOST'} used before. On my Apache server, I wrote a script to print all the keys/values of the %ENV hash and REMOTE_HOST isn't one of them:

Code:
foreach my $key (keys %ENV) {
   print "\$ENV{$key} = $ENV{$key}<br>";
}

The two keys with "remote" in them:

$ENV{REMOTE_ADDR} = 207.74.115.23
$ENV{REMOTE_PORT} = 37437
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top