Visit the Official PHP Website

Search this Site

PHP Programming

By James N Hitz

What is CGI?

CGI is a set of protocols (rules) that allow web clients (your browser) to access and execute programs on the web server, and receive output where it is due.

Where the user has to supply information of some kind to the server (input), it is normally done using HTML forms. The server then passes on this information to a CGI program that executes (runs) and returns output back to the browser if programmed to do so.

A CGI program will normally be created in any language - from C++ to BASIC. It may as well be written in PHP. That's where we come in.

All CGI programs that process form input MUST be put in a special, CGI-enabled directory (folder) on the server. This means that the server will not execute your form-processing CGI scripts unless you place them in a special directory normally called cgi-bin. Matter of fact is, this folder can be named anything. It all depends on personal taste and your server administrator.

IMPORTANT: There are several possible ways of configuring PHP on a web server. This issue cannot be exhausted in the current lesson. Please consult your server administrator and/or the PHP documentation for details.

Why the heck don't they just let the poor CGI scripts run in any folder? Well, you see everyone is not as good as they want you to believe. Some people have malicious intentions and may actually corrupt your system if allowed to run ANY programs. People are NOT TO BE TRUSTED. Not with your precious data!

If you are an administrator of your own, you shouldn't have any trouble with your cgi-bin. Your only concern in this regard is to ensure that your server is secure enough. If you are just one of us poor mortals, you will have to talk real nice to your server administrator and maybe... just maybe he (or she) will create a cgi-bin folder for you - or some other CGI-enabled directory (folder) for your use.

In my examples, I will be using a folder called /php-bin for my PHP scripts (I had to be nice to my server admin).

Well... forgive my cynicism... Let's go on.

<< Introduction to Lesson 6 | About This Lesson >>

JamHitz Productions