CGI(COMMON GATEWAY INTERFACE) may be a set of standards that outline however data is changed from the online server, passing the online user’s request to Associate in Nursing application and to receive data back to the user. When any user requests for a web page, the server sends back the requested page. The Web server typically passes the form information to a small application program that processes the data and may send back a confirmation message. This methodology or convention for passing knowledge back and forth between the server and also the application is termed the common entree interface (CGI) and is an element of the Web’s Hypertext Transfer Protocol (HTTP).
The
Common entree Interface (CGI) may be a set of rules for running scripts and programs on an online server. It specifies what data is communicated between the online server and clients’ net browsers and the way the data is transmitted. Most net servers embrace a
cgi-bin directory within the root folder of every web site on the server. Any scripts placed during this directory should follow the principles of the Common entree Interface. For example, scripts situated within the cgi-bin directory is also given workable permissions, while files outside the directory may not be allowed to be executed. A CGI script may additionally request CGI surroundings variables, like SERVER_PROTOCOL and REMOTE_HOST, which may be used as input variables for the script.
Since CGI may be a normal interface, it will be used on multiple kinds of hardware platforms and is supported by many varieties net server software package, like Apache and Windows Server. CGI scripts and programs also can be written in many completely different languages, such as C++, Java, and Perl. While several websites still use CGI for running programs and scripts, developers now often include scripts directly within Web pages. These scripts, that area unit written in languages like PHP and ASP, area unit processed on the server before the page is loaded, and also the ensuing knowledge is shipped to the user’s browser.
Browsing the Web
For knowing the thought of CGI, let's take a glance at the state of affairs that takes place once users browse one thing on the online employing a specific address.
- The browser you are using contacts the HTTP web server and demands for the URL.
- The web server will parse the URL and will search for the file name; if the requested file is found, immediately sends back that file to the browser or else sends an error message.
- The web browser takes the response from a web server and displays either file received or an error message.
- If you are developing a website and you required a CGI application to control then you can specify the name of the application in the URL (uniform resource locator) that your code in an HTML file.
Server Side Configuration
Before using the CGI programming, programmers should make sure that the Web server supports CGI and is well configured for handling CGI programs. By convention, CGI files will have an extension as .cgi, though they are C++ executable. By default, Apache Web Server is configured to run CGI programs in
/var/www/cgi-bin
Programmers need to have a web server up and running in order to run any CGI program like Perl, shell etc.
Example of CGI program using C++
CPP
// C++ example of CGI program
#include <iostream>
using namespace std;
int main()
{
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>\n";
cout << "<head>\n";
cout << "<title>Hello TutorialsCloud </title>\n";
cout << "</head>\n";
cout << "<body>\n";
cout << "<h3> <b> First CGI program </b> </h2>\n";
cout << "</body>\n";
cout << "</html>\n";
return 0;
}
Output:
Content-type:text/html
Hello TutorialsCloud
First CGI program
CGI Environments Variables
- CONTENT_LENGTH: Optionally provides the length, in bytes. It’s available only for POST requests.
- CONTENT_TYPE: Optionally provides the sort of content i.e. the data type of the content.
- HTTP_COOKIE: come back the visitor’s cookies, if one is ready within the type of key try.
- HTTP_USER_AGENT: The browser type of the visitor. It request-header field contains info concerning the user agent originating the request.
- PATH_INFO: It provides the trail for the CGI script.
- REMOTE_ADDR: The science address of the visitant, i.e. the science address of the remote host creating the request.
- REMOTE_HOST: The hostname of the visitor, i.e. the totally qualified name of the host creating the request
Similar Reads
Socket Programming in C++ In C++, socket programming refers to the method of communication between two sockets on the network using a C++ program. We use the socket API to create a connection between the two programs running on the network, one of which receives the data by listening to the particular address port, and the o
5 min read
C++ Programming Language C++ is a computer programming language developed by Bjarne Stroustrup as an extension of the C language. It is known for is fast speed, low level memory management and is often taught as first programming language. It provides:Hands-on application of different programming concepts.Similar syntax to
5 min read
C++ Programming Basics C++ is a general-purpose programming language and is widely used nowadays for competitive programming. It has imperative, object-oriented, and generic programming features. C++ runs on lots of platforms like Windows, Linux, Unix, Mac, etc.Before explaining the basics of C++, we would like to clarify
8 min read
C++ Programming Examples Writing C++ programs yourself is the best way to learn the C++ language. C++ programs are also asked in the interviews. This article covers the top practice problems for basic C++ programs on topics like control flow, patterns, and functions to complex ones like pointers, arrays, and strings.Basic C
7 min read
Write a URL in a C++ program Writing URLs in programming code doesn't affect the program and the compiler will not throw any error. Here, we will how to use Url in various languages without any errors. The full form of URL is Uniform Resource Locators. URLs are unique they store the address of a particular web application. C++
2 min read
C++ Tutorial | Learn C++ Programming C++ is a popular programming language that was developed as an extension of the C programming language to include OOPs programming paradigm. Since then, it has become foundation of many modern technologies like game engines, web browsers, operating systems, financial systems, etc.Features of C++Why
5 min read