WEB DEVELOPER SITE
PYTHONPHP 7JAVA
 

C++ Web Programming



CGI stands for Common Gateway Interface, is a set of standards that defines how information is exchanged between the web server and a custom script.

First CGI Program

Here is the first CGI program given
/* C++ Web Programming - Example Program */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	cout<<"Content-type:text/html\r\n\r\n";
	cout<<"<html>\n";
	cout<<"<head>\n";
	cout<<"<title>First CGI Program</title>\n";
	cout<<"</head>\n";
	cout<<"<body>\n";
	cout<<"<h2>Hello World, This is my first CGI Program.</h2>\n";
	cout<<"</body>\n";
	cout<<"</html>\n";
	getch();
}
Compile the above C++ code and name the executable as cplusplus.cgi. This file is being kept in the /var/www/cgi-bin directory. Before running your first CGI program, please make sure that you have change mode of file using chmod 755 cplusplus.cgi UNIX command to make file executable. Now if you click on cplusplus.cgi then it will produce the following output:
Hello World, This is my first CGI Program.

HTTP Header

The line Content-type:text/html\r\n\r\n is a part of HTTP header, which is sent to the browser to understand the content.
HTTP Field Name: Field Content
 
For Example
Content-type: text/html\r\n\r\n