Skip to content
  • Home
  • Contact Us
  • About Us
  • Privacy Policy
  • DMCA
  • Linkedin
  • Pinterest
  • Facebook
thecscience

TheCScience

TheCScience is a blog that publishes daily tutorials and guides on engineering subjects and everything that related to computer science and technology

  • Home
  • Human values
  • Microprocessor
  • Digital communication
  • Linux
  • outsystems guide
  • Toggle search form

What is Common Gateway Interface (CGI)

Posted on March 30, 2021November 20, 2022 By YASH PAL 15 Comments on What is Common Gateway Interface (CGI)
The Common Gateway Interface (CGI) is an accepted standard for interfacing Web servers and external applications. Web servers and external applications. Web servers were originally designed to serve static HTML documents along with other associated static files. A web browser that communicates with a Web server limits its functionality to serving static pages.

It displays only documents whose contents will not change between requests or during page visualization. However, CGI established a standard for information to be exchanged between Web servers and browsers. CGI allows the passing of information between a browser or server to an external program that performs some actions. it then outputs its results back to the user’s browser.
What is Common Gateway Interface (CGI)
CGI (Common Gateway Interface) is a standard whose specification defines a way for Web servers to communicate with external programs, and vice versa. with this method, the external program can generate HTML, images, etc. for the server for its processing.

Table of Contents

  • Why CGI?
    • Scope of CGI
    • How does CGI Function?
    • CGI Methods
      • GET Method
      • POST Method
      • HEAD Method
    • CGI Libraries
    • CGI Libraries for C Programming.
    • CGI-HTML Library
    • The C++ CGI Class Libraries
    • Using CGI for Web site Linking

Why CGI?

CGI is used to generate dynamic content with the same ease that you generate static content. it is a very well-defined and supported standard, and without CGI, dynamic content would have been impossible without proprietary server methods. There are many useful applications of CGI programs.

An example of a simple task would be a hit counter. these are CGI scripts are written in either Perl, C, or maybe just a simple shell script, but they all basically work the same way. they keep a single data file that stores the number of hits. the program reads that data file and when called, increments the number by one and then returns that number. the code to counter can be found at ftp://server.berkeley.edu/pub/www/counter.

CGI is obviously not the only method for creating counters, but as things stand today, it is the best, for three main reasons. the first, because it is currently the quickest. The second reason is that the CGI standard is the most compatible with today’s browsers. CGI is a technology that interfaces with HTML. CGI applications generate HTML or images. The third reason is availability. CGI-based counters and CGI code to perform simple tasks are available in plenty.

It is always easier to use code already written than it is to write your own. This (the prewritten code) is a major factor as to why simple tasks are coded in CGI. They are already done by someone else, usually include sample documentation and commented source code, and are waiting for you to just implement them on your server.

The next stage of tasks is the creation of image maps and animation. While basic image mapping requires no programming when done on the client side, doing something more than just jumping to an HTML page when you click on an image requires programming. CGI uses up a lot of processing time. Java consists of real, live applications embedded into the Web page and is therefore fully interactive.

The advanced tasks are currently a lot easier to perform in CGI than in Java. Examples of such tasks include Database Backending, Search Engines, and Multiple Dynamic Pages. CGI programs can do many things on many platforms. In fact, one of the major features implemented in servers supporting CGI specification is that the programs can be written in any language and on any platform as long as they conform to the specification. By comparison, most server extensions are proprietary and specific to one server software, one platform, or both. This means that it is not specifically tied down to the PC, as is VBScript.

Scope of CGI

Basic CGI applications are extremely easy in C, C++, Shell Scripting, and Perl. CGI’s usefulness ends on the Web page. After you leave the idea of generated documents that do not change after they are generated (in terms of that specific instance of loading of page), CGI is worthless. Real live applications embedded on Web pages are the realm of languages such as ActiveScript and Java.

The usefulness of CGI is a standard to programming because it varies from task to task. The other point is that CGI is a relatively old technology. But, as newer technologies, such as the Java programming language grows up, they may eventually make CGI absolute.

How does CGI Function?

Imagine that you have a product database on your system that you would like users on the Web to use, but your Web server does not understand the database internals. You must link both the Web server and the database by using a CGI program. This special-purpose program may be developed by you or provided by the database vendor and will be responsible for the database queries on one hand, and the communication with the Web server on the other hand. This last functionality works only because the Web server and the program have established rules for communication between the two. The rules that make them able to interface are called the Common Gateway Interface.

The Web Servers are usually with a set of general-purpose CGI programs that reside in a CGI-bin directory, within the Web serve root directory. This is the directory commonly used for CGI program storage, but the Webmaster can define other locations. CGI applications can be written in any language that can be executed on a computer, particularly a Web platform. In fact, you can choose any of the common languages for your CGI applications.

Your choice depends on what you have to do because different languages may be specialized for different purposes. Perl, for instance, is great for string and file manipulation, while C is better for bigger, more complex programs. Perl and C are probably the most used languages for CGI programming.

CGI Methods

A method is a way of invoking a CGI program. There are three main methods. These are:
  1. GET Method
  2. POST Method
  3. HEAD Method

GET Method

In the GET method, the CGI program receives that data in the QUERY_STRING environment variable. The program must process the string to interpret the data and execute the needed actions. The GET method should be used when you want to obtain data from the server and you will not change any data on the server.

POST Method

When you use the POST method, the Web server transmits the data to the CGI program through the stdin (standard input). The server does not mark the end of the data with an EOF character, so the program must use the CONTENT_LENGTH value to read the stdin correctly.

You should use the POST method when the data you send will alter any data on the Web server or when you want to send large amounts of data to the CGI program (usually, more than 1024 bytes, the length limit of a URL).

HEAD Method

The HEAD method is similar to the GET method, except that with the HEAD method, only the HTTP headers (and not the data itself) are sent by the Web server to the browser.

CGI Libraries

There are many languages used for CGI programming. with each of these different languages, there is almost always more than one library for CGI.

CGI Libraries for C Programming.

CGI libraries for the C language (CGI) are the best to be used for the following reasons as they
are actively maintained,
have great documentation,
have good support.

CGI is moderately easy to use, and hence the best all-around choice. CGI has the following features:
  1. Some advanced form handling.
  2. can handle all of the CGI environment variables.
  3. can perform automatic redirection.
  4. can output HTTP error/status codes instead of a document.
  5. allow capturing CGI sessions for later playback/debugging as well as a full features error handling system.

CGI-HTML Library

It is still in major development and does not offer priority support. it offers source code, and it is completely free. The following are the features of CGI-HTML:
  1. It has the most advanced form handling of any of the libraries.
  2. It can handle all of the CGI environment variables.
  3. It can perform automatic redirection.
  4. It can output HTTP error/status codes instead of a document.

The C++ CGI Class Libraries

An HTML is one C++, CGI class library. Following are the features of A HTML:
  1. constantly updated.
  2. contains many neat features.
  3. very easy to use.
  4. can handle all CGI environment variables including arrays, matrices, and linked lists.
  5. contains classes for handling bitmaps and other image types.
  6. can output HTTP error/status codes instead of a document.
The documentation for this library is written for programmers, but it does include examples for every class.

Using CGI for Web site Linking

One of the most useful applications of the Web is its capability to link a Web site with a database so Web surfers can search for information. In essence, the Web page becomes the front end for database applications, enabling you to select search criteria and execute even complex searches of a database that resides on the host computer.

Linking a Web site to a database can be relatively simple. The database can take just about any form and can be as simple as FileMaker Pro data as or as complex as an Oracle SQL database. The bridge that brings together Web sites and databases is the CGI. One well-known example of linking between websites and database is the popular Yahoo! Web site. The Yahoo! site serves as a front end to an extensive database of Web site descriptions, which can be searched according to keywords.

On the client side of the database, you see a Web page that includes a form in which you enter your search terms. By executing the search, you launch a CGI script that sends a search command to the Web server in the form of a link to the CGI bin on the Webserver. So a search on the Yahoo! site for public relations firms looks like the following:
http://search.yahoo.com/bin/search?p=the+computer+science

When the Web server receives this URL, it identifies the URL as a trigger for a CGI script and passes it along with the search criteria to the mini-program using CGI. The CGI script then sends the search to the database, receives the results of the query along with the HTML page created by the database to contain the result, and passes it on to the Web server to be sent back to the client. All of this happens behind the scenes.

Also, read
  • Characteristics of internet
  • Structure of internet
Digital communication, internet Tags:Digital communication, engineering subjects, internet

Post navigation

Previous Post: Virtual Reality Modeling Language – DC
Next Post: Cloud Computing Characteristics

Related Posts

Memory Organization in 8085 Microprocess engineering subjects
Structure of Internet Service | Digital Communication Digital communication
Understanding the Harmony in the Society engineering subjects
Trust and Respect as the Foundational Value of Relationships engineering subjects
Types of Firewalls | Digital Communication Digital communication
Basic Computer Structure – Overview computer fundamentals

Comments (15) on “What is Common Gateway Interface (CGI)”

  1. schelling says:
    November 15, 2022 at 9:04 AM

    WОW ϳust what I was looking for. Came here by searcһing fοr gruff

    Reply
  2. YASH PAL says:
    December 7, 2022 at 10:28 AM

    it’s hostinger

    Reply
  3. проведение опрессовки системы отопления says:
    December 12, 2022 at 1:49 AM

    Thanks for a marvelous posting! I actually enjoyed reading it,
    you are a great author. I will remember to bookmark your blog and will come back later on. I want to encourage one to continue your great writing,
    have a nice day!

    Reply
  4. http://ivistroy.ru/ says:
    December 12, 2022 at 2:32 AM

    Wonderful blog! I found it while surfing around on Yahoo News.
    Do you have any tips on how to get listed in Yahoo
    News? I’ve been trying for a while but I never seem to
    get there! Cheers

    Reply
  5. http://masterok-tut.ru/ says:
    December 12, 2022 at 12:17 PM

    When someone writes an article he/she retains the plan of a user
    in his/her brain that how a user can know it. Therefore that’s why this paragraph
    is perfect. Thanks!

    Reply
  6. http://smartremstroy.ru/ says:
    December 13, 2022 at 7:03 PM

    Heya i am for the first time here. I found this board and
    I find It really useful & it helped me out much. I hope to give one thing again and help others like you helped me.

    Reply
  7. http://ktopovar.ru/ says:
    December 13, 2022 at 9:36 PM

    Hurrah! After all I got a web site from where I know how to really take valuable facts concerning my study and
    knowledge.

    Reply
  8. hay day скачать на компьютер says:
    December 17, 2022 at 1:41 PM

    I think the admin of this web site is truly working hard in support of
    his web page, because here every information is quality based stuff.

    Reply
  9. Гостиничные чеки в Екатеринбурге says:
    January 30, 2023 at 12:36 PM

    We are a group of volunteers and opening a new scheme
    in our community. Your web site provided us with valuable info to work on. You have done
    a formidable job and our entire community will be thankful to you.

    Reply
  10. кариес зубов лечение says:
    February 4, 2023 at 12:02 AM

    No matter if some one searches for his vital thing, so he/she needs to be available that in detail, so
    that thing is maintained over here.

    Reply
  11. кариес зубов лечение says:
    February 4, 2023 at 10:20 AM

    Hi, I want to subscribe for this webpage to get latest updates,
    so where can i do it please help out.

    Reply
    1. YASH PAL says:
      February 4, 2023 at 1:16 PM

      Here- https://www.youtube.com/@programmingoneonone

      Reply
  12. увеличение губ филлером says:
    February 4, 2023 at 10:26 AM

    A person essentially lend a hand to make significantly articles I’d state.
    That is the first time I frequented your web page and up to now?
    I surprised with the research you made to make this particular put up extraordinary.
    Great task!

    Reply
  13. увеличение губ филлером says:
    February 4, 2023 at 10:51 AM

    Its like you read my mind! You seem to know
    a lot about this, like you wrote the book in it or something.
    I think that you can do with some pics to drive the message home a bit, but other than that, this is excellent blog.
    A fantastic read. I’ll certainly be back.

    Reply
  14. карта мира на стену из дерева says:
    March 20, 2023 at 1:49 AM

    I quite like reading through an article that will make people think.
    Also, thank you for allowing for me to comment!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Pick Your Subject
Human Values

Copyright © 2023 TheCScience.

Powered by PressBook Grid Blogs theme