Saturday, November 16, 2024
Google search engine
HomeLanguagesHow to create a simple CGI script?

How to create a simple CGI script?

In this article, we will explore how to create a simple CGI (Common Gateway Interface) script on a Windows machine but before that, we need some basic ideas about these technologies ( CGI Script, HTTP, Web Server ).
CGI Script: A CGI script is a program that runs on a web server and generates dynamic web content. It’s often used for processing web forms, interactive web applications, and server-side tasks.
HTTP: Hypertext Transfer Protocol is the foundation of data communication on the World Wide Web. It defines how messages are formatted and transmitted.
Web Server: A web server is software that serves web content to users, listening for incoming requests and responding by delivering web pages or running CGI scripts.

Prerequisites: Please ensure that XAMPP is installed on your machine before continuing. If not then please refer to XAMPP installation in Windows.

Creating CGI Script

We’ll use the CGI directory provided by XAMPP “C:\xampp\cgi-bin” for storing the CGI script.

b1

Now create a new file with a .cgi extension and paste the following code into this new file.

q3

#!"C:\xampp\perl\bin\perl.exe"
print "Content-Type: text/html\n\n";
print "<h1>Geeks For Geeks</h1>";
print "<p>This is a cgi-script</p>";

q1

Running and Testing the CGI Script

In this section, we will run and test our CGI Script on web server using XAMPP.

Step 1: Open XAMPP Control Panel from the start menu.

b4

Step 2: Click Config for the Apache module

b5

Step 3: Select Apache (httpd.conf) to edit the configuration file

b6

Step 4: Uncomment the line #AddHandler cgi-script .cgi .pl .asp

In this step, we will uncomment the line #AddHandler cgi-script .cgi .pl .asp if commented otherwise remain it as it is.

b7

Step 5: Save the file and restart the Apache server

We will save the file and then restart the apache server such that the changes become save and Apache will run according to those changes.

b8

Step 6: Access the script

We can access the script through a web browser by navigating to “http://localhost/cgi-bin/gfg.cgi” in our Chrome web browser.

q2

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments