Home
Username:
Password:
Web Publishing and Publicizing Tutorials

Web Concepts and Technologies / CGI Scripts

Subtitles of the Movie

Now there is substantially more to developing a website then simply creating html pages and the images they contain. For the rest of this chapter, we’ll have a look at some of those things which you can add to a website. The first of these is what we call a CGI script. What’s a CGI script? CGI stands for common gateway interface. The CGI script used in conjunction with your website is a way that you can add functionality to your website. Typically a website that doesn't have any of this kind of functionality is what we might call a display only website. This means that the people who come to your website can simply look at it, they can click on some links to look at some other pages but really that's all they can do. Click on various links and look at various pages. If you do it right, you can add CGI scripts in such a way that your website can become more functional. We'll have a look at some examples of that in a moment. First what is a CGI script exactly? Well it's a program. Some kind of program written in a programming language. Which programming language? Well we’ll have a look at that in a moment. There is a bunch of them. So in order to write a CGI script, you have to be some kind of programmer. That doesn't mean you have to go off to college for five years and learn programming that way. Some of these CGI scripting languages are very simple and you can learn them in a day or less. Most common of these is called Perl. Perl is a programming language; it's a scripting language, Perl is a short for practical extraction and reporting language. Perl's strengths lie in the way that it can take input from a web page, I’m talking about input that a user, the person is browsing a web page might have entered into the web page, might take that sort of input and then perform some simple operations like generating an email and ultimately generate an html page that the user can then look at, which could, they could view as the results of their operation. I'll show you an example of this in the next module when we look at forms. Other languages that you can use as a CGI script besides Perl include C, C++, Python, AWK, TCL any Unix shell such as the Baun Shell, the Caun Shell, C shell, In fact you can make a CGI bin program out of just about any programming language if you do it right. So if you’re already a programmer and know one of these languages, you may be able to adapt that programming into the CGI framework. It’s important to understand that CGI scripts are all what we call server side scripts. This means that the scripts reside and run on the web server. Well where else could they run? They could run on your machine, they could run on the browser, they could run on the person's machine who is viewing the web page. Those are called client side scripts and CGI scripts are not those. I might just take a moment to describe the difference between server side and client side programs. We've got a client server environment where we’ve a client that's requested some information from the server, so we've got at least two machines involved here, we've got the client machine and we've got the server machine. If some script or other program has to run, it has to run either on the client machine or on the server machine. The client machine might be a windows 95 or it might be a Macintosh could be any thing really, where as the server machine is likely to be one of those industrial strength server types of operating systems like Unix or Windows NT or perhaps Linux or something like that. Various programs run on various operating systems. Some programs will run on the client, some programs will run on the server, it’s important that you understand that this is something that you the website developer have to keep in mind when you’re adding functionality to your website in the form of a script or program. We will look at some examples of client side scripts, which are in the sections of JavaScript and VBScript, they’re a little bit later on. So the bottom line is a CGI script, a CGI program will run on the server. So if it's a Unix server and they usually are if they’re running CGI scripts, then the program that runs must be a Unix program of some description, and Perl is a Unix program. There are derivatives of Perl that will run on Windows but they usually run on Unix. If you want server side functionality in your website, CGI scripts is not the only way to go, we'll look at some others in particularly we'll look at what we call asps or active serve pages. We’ll see those in a moment. So what can you do with a CGI script? What's this functionality that I’ve been talking about, well you could use a CGI script to give your website a hit counter. You know those little counters at the bottom of the web page that says you are visitor number 3,820 to this web page. Those things, it's a hit counter, you can use CGI scripts to give you those. A poll, you can have a poll on your website saying do you think this web page is really, really good, yes, no, maybe, that kind of stuff and they click on the various option and your CGI script would collate the results. You can use CGI scripts to password protect various areas of your website, you can say, have a page saying, ‘you cannot proceed to this page you’re requesting until you enter the password’ and the CGI script would verify the password for you. You can create feed back forms where you can get people to enter what they think about various things, they can request more information request technical support and the information that they entered can then get added to a file on the server, it could get emailed to a particular email address, it’s completely up to you, depends on the CGI script. You can even set up things like e-commerce where people can create shopping carts full of the things that they want to buy, you can add how much they’re going to cost and that sort of thing, not to mention databases. You can get your CGI scripts to retrieve information out of a database and display the results of the database query on a web page. So a CGI script is very flexible, very powerful technique for adding functionality to an otherwise display only website. So how do CGI scripts work, what is the process involved? How does the user get a CGI script to run? Well it works like this, firstly an html page that contains a reference, mind you it’s only a reference to a CGI script is opened in a browser So we've got an html page somewhere, a page that you will have designed and in there is the name of a CGI script that is residing on the server. and the html page gets opened in the browser, that does not necessarily cause the CGI script to run straight away. In fact it usually doesn't unless it was a hit counter or something like that. Usually the page is opened first and the script is run later by say it might be a button, a submit button or something like that and the user clicks on that button and that causes the script to get run because it works like this. When they click on that button, whatever it might be that has the reference to the script and the browser has to find that script, so the browser goes and connects to the server again and this time instructs the server not to retrieve a web page but to run a particular CGI script and the browser may actually pass some information that was on the page back to the script, so that the script can run in a more particular fashion. And so the script runs. Now what will often happen at this point is that the script will actually generate another html page and the browser will be taken to that html page and so the person using the browser will see another page. This page might say something like ‘thank you for your feedback’ or it might say ‘thank you for voting in our poll’ or it might say ‘your shopping cart is now being updated’ or something of that nature. So the bottom line is it works like this, the user clicks on something on the web page usually, this causes the browser to connect to the server and instructs that a script be run on the server, the server generates, sorry the script that is running on the server generates another html page, which is then displayed in the browser. We’ll look at a typical example of that in the next module, the next module is called forms.

Tutorial Information

Course: Web Publishing and Publicizing
Author: Mark Virtue
SKU: 33298
ISBN: 1930519729
Release Date: 2002-03-11
Duration: 6 hrs / 61 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available