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

New to CGI - Please help!

Status
Not open for further replies.

masterzin

IS-IT--Management
Sep 26, 2007
6
US
Hi there, I am new to CGI and have not really worked with web devolepment in the last 4 years. I am now tasked with implementing some polling items through the use of CGI on our internal web site.

I have installed PERL and I am trying to use CGI to post these scrips to run, however I am getting nowhere. I downloaded some different scripts off of free CGI sites but I can not implement them.

My first and main question is what does the first line of code mean in the script? IE: #!/usr/local/bin.perl

I can not seem to find out what this is attempting to reference. I installed a copy of ActivePerl in hopes that it was just a matter of the program not being installed at all, but this did not resolve the issue either. Any help or direction would be greatly appreciated.
 
It is the location of the perl interpreter on your machine. For windows it is normally something like
#!c:/perl/bin/perl.exe
(don't mind the slashes.. perl expects unix style slashes even though your on windows).

You check that your scripts work from command line first then try them through the website.

You can do something very simple like

#!c:/perl/bin/perl.exe
print "Content-type: text/html\n\n";
print "<html>This is a test</html>";

I would suggest you look at the CGI module for doing web based stuff. If you are using activestate you can start the "perl package manager" and install your modules (you will NOT be using CPAN for your modules). If you are behind a proxy (that isn't transparent) you will need to create a env varialbe called http_proxy and give it the value of your proxy.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
I placed the code that you gave me into a web page but it did not work. What format am I supposed to be creating this in? Do I need to place those commands into a text file, or can I just drop them into the HTML code? I can read what is trying to be done here just fine. The problem is that when I save this to a web page and attempt to prieview, all I see is the code itself.

By the way, I appreciate the quick help and response!
 
They need to be in a .txt file that is named .pl or .cgi (depends on your web server). THey will need to be in the cgi-bin directory. You need to make sure that the very first line is the #! line.. no blank lines allowed above it. What web server are you running?? IIS or Apache are the biggest.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
So I did as instructed and I still am not able to get it to work. Just so you know, I am running Front Page 2003 with ActivePerl installed and IIS. Here is my directory in Front Page:

---cgi-bin
---test.cgi
...

test.cgi contains:

#!c:/Perl/bin/perl.exe
print "Content-type: text/html\n\n";
print "<html>This is a test</html>";

What I am doing is trying to "preview" the .cgi file. Is this the correct way to do this or am I missing something entirely? When I try to open the .cgi file with the command prompt, it asks me which program I want to open it with and if I select Word, or my browser it gives me the following:

#!c:/Perl/bin/perl.exe
print "Content-type: text/html\n\n";
print "<html>This is a test</html>";

So the print "This is a test" is not comming out alone, I get the whole string. Sorry to keep bothering you but thanks for the help, it is great!
 
you can test it by typing from a command line

perl test.cgi

it should run and print the two lines successfully.

The only real way to look at it via a browser is via the web site (assuming it is running locally and listening to the loopback).



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
GREAT! Well, I tried the:

perl test.cgi and I got the following

Content-type: text/html

<html>This is a test</html>

So thats definetly progress :) As far as integrating CGI scripts into my webpage though, how do I start tackling there? What I am really wanting to do is download free CGI scripts, or write my own and then implement them through forms onto my webpage. The end result functionanlity that I am needing is to be able to set up polling and surveys for the employees to do each morning.

Thank again!
 
THe next step is to verify you can see it via your web site..
so you will do and see what it does. After that you should be good to go to write your own or install some others.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
When I test it in my web page I get:

#!c:/Perl/bin/perl.exe print "Content-type: text/html\n\n"; print "This is a test";

This is all on one line.
 
You probably need to take this to a IIS forum or a perl forum. It's more of an IIS configuration problem though.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Sounds good, hey thanks for all the help though. I really did learn a few things that I was not aware of before!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top