What is cgi and how to use your cgibin cgi tutorial
On the user's PC by their browser. The best book out there for beginners, including those who don't know a lot about programming. Perl for Dummies comes with a CD that includes sample code and a copy of Perl-Win32 that you can use on your Windows-based system to test your scripts. The book covers using the Perl-Win32 software also. It doesn't get into the real fancy Perl functions but that's not its' goal.
It's an "easy read" that will have you coding in no time. If you're an experienced programmer this may be a good starting point for you. Mastering Perl is very comprehensive in it's coverage of Perl, addressing functions that the "Dummies" book doesn't get to.
The information is presented in a very easy-to-understand manner and doesn't assume you have a UNIX background. A lot of the more advanced books do.
They also cover Blat and Sendmail for Windows. I wish every programming language had a book like this. Effective Perl Programming is a unique work that will make a Perl programmer a good Perl programmer. The CGI application we will develop will take 2 forms, a text based counter, and a program that shows you how to get input from the HTTPD, so you can use it in your program. So without further ado, lets get on with the article.
All programs are run on the server side, unlike java, and prettymuch any language can be used for developing CGI. The CGI interface as it applies to input consists of a set of environment variables which can be retrieved and used by the CGI application, thereby allowing us to get information from the client. This probably means nothing to you, but as we go on it will. There are many headers that are valid to CGI and they are as follows: Content-type - A header used to tell the HTTPD what type of data to expect so it can parse it and output things properly.
So, basically, the CGI output consists of a header, two newlines and your appropriate data, and thats it. You could also add text manipulation tags, infact you could add your entire page as the CGI, however it would be a waste of time to do so.
So continuing on, youve now got a small grip on CGI and how it works, so lets describe the input. There are quite a few variables to choose from, each giving you valuable information that you might be able to use to your advantage. We will cover each of them here, and possibly some you might not find in NCSA's own documentation woo! This is mainly because we will be using them all in our program to display them.
I won't go into how getenv works you can check your helpfile, C-Book or manpage for that. I will however list the variables that you can access: For example "NCSA 1. It is then stored in this environment variable. It should not be decoded in any fashion when it gets to you, which means of course youll have to decode it. Usage of this variable should be limited to logging only and is not suggested for authentification purposes as identification can be faked easily.
Each item in this list is seperated by commas. This of course will be nothing if you happen to just access the script instead of accessing it from an html document. These are all variables which return the information that you have in the description of them all through the use of getenv. Above and beyond that, for input HTTPD has its own encoding, which you have to handle yourself, it's pretty simple to handle and only has a few quirks, basically you dont need to know any of this until you cover forms and cgi, which will be my next installment of this document in the next CScene.