#webtech2

Thread

Nityesh Agarwal February 25, 2020 at 07:20 PM

CGI (thread):

Nityesh Agarwal February 25, 2020 at 07:20 PM

Full form - Common Gateway Interface

Nityesh Agarwal February 25, 2020 at 07:25 PM

Principles of CGI programming:

• it defines how information is transferred from web server to an external application and external application to web server
• Independent of any programming language - external applications may be developed using a programming language that fits the application

Nityesh Agarwal February 25, 2020 at 07:29 PM

Advantages:

• It provides a very simple interface for making http requests to web server.
• It is not necessary to have any special library or any api to make a CGI.
• CGI programs rely on the standard concepts of standard input, standard output, and environment variables to communicate with the Web server.
• Independent of any programming language - external applications may be developed using a programming language that fits the application

Nityesh Agarwal February 25, 2020 at 07:35 PM

Structure of a CGI program

Any CGI script consists of basically three steps:
• Read parameters passed to this script
• Process these parameters
• Write HTML response to the standard output
Example:

```#include <stdio.h>

include <stdlib.h>

int main(void) {
long a, b;
printf("Content-Type:text/html\n\n");
char *data = getenv("QUERY_STRING");
sscanf(data,"a=%d&b=%d", &a, &b);
printf("%d + %d = %ld", a, b, a + b);
return 0;
}```

Nityesh Agarwal February 25, 2020 at 07:41 PM

How to distinguish if a request is a CGI request or not?

> The server needs a way to know which URLs map to scripts and which URLs just map to ordinary HTML files. For CGI this is usually done by creating CGI directories on the server. This is done in the server setup and tells the server that all files in a particular top-level directory are CGI scripts (located somewhere on the disk) to be executed when requested. Moreover, Some servers can also be set up to not use CGI directories and instead require that all CGI programs have file names ending in .cgi.

Paridhi Agarwal February 26, 2020 at 05:28 AM

4b