Cgi is a program that runs on a web server
and produces html
web pages dynamically just before web server wants to send
it to you.
Web server is responsible for running Cgi program and
gathering its output results and forming it as a html page
and sending it to web browser over internet connection.
Cgi-bin programs can be written in almost every programming
environment that is able to produce console binary
executables.Cgi-bin programs produces html text and web
server sends resulting html. As pages are produced by a
program they can change dynamically. For example they can
contain search results on a database .
In the other side there are programming languages like
"Perl" that do not produce binary executables. Perl programs
run with Perl interpreter assistance. Same as cgi-bin these
programs make dynamic html pages. As they are not compiled
we call them "Cgi" programs .
Below you will see two sample programs in C. They will compile
to binary executables so they will produce cgi-bin programs.
First program is written for cc or gcc under Unix operating
system. You can run it under any Unix web server capable to
run Cgi programs. Under Unix you must be sure that Cgi program
has execution permission.
#include<stdio.h>
main()
{
printf("Content-type: text/html\n\n");
printf("<html><H1>Hello
World!</H1></html>");
}
Second program is a Visual C++ console application that can
be run with IIS or any other windows web server.
#include "stdafx.h"
#include<stdio.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
printf("Content-type: text/html\n\n");
printf("<html><H1>Hello
World!</H1></html>");
return 0;
}
If you have more questions about Cgi programs you can visit
our support forums and subscribe to our Cgi mailing list.
To visit our site go to :
http://op.htmsoft.com
|