|
About CGI scripts You can't use a form without a CGI script. Hey, don't worry, it's not that bad. What is a CGI script? If you're a non-programmer, the phrase CGI script may make you want to quickly forget about forms altogether. Hold on. What's CGI? What's a script? It's not as impossible as it sounds. First, a script is another word for a program, just like Microsoft Word or Adobe Photoshop. Of course, the script you'll use to process forms are a good deal simpler than commercial applications that cost hundreds of dollars. But they work in a similar way. CGI, which stands for Common Gateway Interface, is simply a standardised way for sending information between the server and the script. So to resume, a CGI script is a program (usually written in a programming language called Perl) that communicates with the server in a standard (CGI-like) way. What does the CGI script do? Each element on your form will have a name and a value associated with it. The name identifies the data that is being sent. It might be something like visitor_name. The value is the data (say, Castro), and can either come from you, the Web page designer, or from the visitor who types it in a field. When a visitor clicks the submit button (or an active image), the name-value pair of each form element (it might look like visitor_name=Castro) is sent to the server. The CGI script takes all the name-value pairs and separates them out into something a real human (or a database) can read and understand. GET vs POST There are two ways to send information to the server: GET and POST. It's important to know the difference because you'll have to decide which one is used when you set up the form. The GET method appends the name-value pairs to the end of the URL. This information is then passed to the QUERY_STRING variable. The CGI script must then break down the QUERY_STRING environment variable to analyse the incoming data. The principal disadvantage of the GET method is that the amount of data you can retrieve is limited. Its chief advantage is that you can create a link that accesses a CGI script. The POST method sends a data file with the name-value pairs to the server's standard input, together with the Content-Type and the Content Length in bytes. The CGI script then takes the data from standard input and analyses it. The principal advantage? No size limit. Which one should you use? If you want to make a link to a CGI script, use GET. If you're worried that the data will be truncated, use POST. The most important thing is that the CGI script that you use knows how to parse information gathered with the method that you choose. Security Before you get too excited, you should know that CGI scripts can leave your server wide open to invaders. That's the reason many ISPs do not allow their users to use CGI scripts. If this is your case, one alternative is to use a form hosting service. Getting a script If you ISP okays your use of CGI scripts, your next step is to get your hands on one. If you're a programmer, you can write your own. If not, you can find scripts on the Web and adapt them for your own use. Perl is the most common language used for CGI scripts, partly because it's easily ported from one platform to another, partly because it's great for massaging data into understandable information, and partly because it has this reputation as a cool language-really! Perl programmers love to brag about how they can do anything with Perl, on one line, in a million different ways. You can use other programming languages, like C++, tcl, Visual Basic, or even AppleScript to create CGI scripts. One extra nice thing about Perl programmers is that they like to share. You can find tons of ready-to-use CGI scripts written in Perl all over the Web. |