The Wayback Machine - https://web.archive.org/web/20240927011028/https://www.geeksforgeeks.org/how-to-create-a-simple-cgi-script/
Open In App

How to create a simple CGI script?

Last Updated : 27 Sep, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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



Similar Reads

How to Create Form using CGI script
HTML forms are a fundamental part of web development, allowing users to input data and interact with web applications. Web developers often use Common Gateway Interface (CGI) scripts to process and send the data submitted through these forms. In this article, we'll explain what Python CGI scripts are and guide you through how we can create a form u
3 min read
What is CGI in Python ?
CGI stands for Common Gateway Interface in Python which is a set of standards that explains how information or data is exchanged between the web server and a routine script. This interface is used by web servers to route information requests supplied by a browser or we can say that CGI is customary for external gateway programs to interface with in
3 min read
Historical context and evolution of CGI.
When you click on any of the links on the webpage, your browser contacts the HTTP web server and demands the URL that is, the filename, and the web server passes the URL and looks for the filename, if it finds that file, it will send it back to the browser otherwise sends an indicating message that you have requested a wrong file. Then, the web bro
12 min read
CGI vs Client-Side Scriting ( Javascript)
In the ever-evolving world of web development, two fundamental technologies play a crucial role in enhancing user experiences and enabling dynamic web applications: CGI (Common Gateway Interface) and Client-Side Scripting, often powered by JavaScript. These technologies serve different purposes and have distinct characteristics. In this blog, we'll
3 min read
How to handle form data in CGI Scripts?
In this article, we'll guide you through the process of creating a registration form in HTML and then using a CGI script to fetch and display the submitted user data in the form of a card, along with a success message. Registration forms are a fundamental component of many web applications, allowing users to provide essential information for access
4 min read
Emerging technologies and trends in CGI programming
In the ever-evolving global generation, Computer-Generated Imagery (CGI) programming isn't any exception to the rule of thumb. CGI has come a prolonged way due to the fact its inception, and it continues to strengthen at a mind-blowing pace. This article explores the growing era and trends in CGI programming, shedding light on the thoughts, and ste
7 min read
How to generate dynamic content with CGI?
In this article, we will explore how we can generate dynamic content with CGI (Common Gateway Interface) script on a Windows machine. We will create a webpage in which various user interactions can be performed, dynamic data is been displayed as per user input. CGI Script: A CGI script is nothing but a program that is executed on the web server and
4 min read
Handling File Uploads via CGI
In this article, we will explore how we can handle file uploads via CGI (Common Gateway Interface) script on Windows machines. We will develop a form in which there will be the functionality of uploading the file, when the user uploads the file and submits the form, the data is been passed to the CGI script and the file that is uploaded will get st
6 min read
What is the role of CGI in Web development?
CGI stands for common gateway interface. It is an interface that enables the web server to process a user's HTTPS request by executing a program. It executes a program that resides on the server to process data to produce the relevant dynamic content. When a client gives a request or input, this data is passed to the CGI script as an environment va
6 min read
GET and POST in Python CGI
In this article, we will explore the GET and POST methods in CGI. In Python, the Common Gateway Interface (CGI) plays an important role as it enables and helps in the creation of dynamic web pages. It basically allows Python scripts to be executed and run on a web server in response to a client's HTTP request. if you are learning networking for the
5 min read
How To Enable or Disable CGI Scripts in Apache?
This article will guide you on how to enable or disable CGI scripts in Apache. Configuring CGI scripts in Apache is a crucial aspect of managing dynamic content generation on web servers. The Common Gateway Interface (CGI) provides a standardized protocol for executing programs, allowing websites to produce dynamic output. Whether enabling or disab
4 min read
How to generate webpages using CGI scripts?
In this article, we will explore the process of generating webpages using CGI scripts. Furthermore, we will discuss the importance of CGI script implementation in facilitating dynamic content creation. Additionally, we'll delve into the intricacies of linking one page to another by creating multiple pages within Python CGI scripts, ensuring a seaml
4 min read
How to generate basic HTML output using CGI scripts?
In this article, we will explore the process of generating basic HTML output using CGI scripts. Specifically, we will focus on creating a simple HTML web page using Python. The objective is to provide a step-by-step walkthrough, detailing the entire process of creating and utilizing CGI scripts to generate HTML content within a web environment. Wha
3 min read
How to Execute SQL queries from CGI scripts
In this article, we will explore the process of executing SQL queries from CGI scripts. To achieve this, we have developed a CGI script that involves importing the database we created. The focus of this discussion will be on writing code to execute SQL queries in Python CGI scripts. The initial step involves creating a database, and it's worth noti
5 min read
CGI Programming in Python
What is CGI? Common Gateway Interface (also known as CGI) is not a kind of language but just a specification(set of rules) that helps to establish a dynamic interaction between a web application and the browser (or the client application). The CGI programs make possible communication between client and web servers . Whenever the client browser send
5 min read
How CGI Scripts recieve data from HTML forms?
In this article, we will see how we can revive the data from HTML forms in CGI Scripts (Common Gateway Interface). We will perform the demonstration on a Windows Operating System machine. We will create a basic HTML form and a CGI script using Python, which will handle the data revived from the HTML form. Related Concepts CGI Script: A CGI script i
5 min read
Python | Create simple animation for console-based application
As we know Python is a scripting language, and can be easily used to automate simple tasks. In this article, we will learn how to create a simple console-based animation, which can be used while developing a console based project as a utility. We will try to replicate the loading animation as shown below: We will be using following modules - sys mo
2 min read
Create a Simple Two Player Game using Turtle in Python
Prerequisites: Turtle Programming in Python TurtleMove game is basically a luck-based game. In this game two-players (Red & Blue), using their own turtle (object) play the game. How to play The game is played in the predefined grid having some boundaries. Both players move the turtle for a unit distance.Now both players flip the coin:if HEAD, t
4 min read
How to create a simple drawing board in Processing with Python Mode?
Processing is a programming language, and a development environment. It is an open-source software to create visual arts, graphics and animation using programming. It supports around 8 different modes, and in this article, we will be using Python Mode. In this article, we are going to create a simple drawing board using Processing with Python Mode.
3 min read
Create a Simple Sentiment Analysis WebApp using Streamlit
In this article, we will see how we can create a simple Sentiment Analysis webApp using with the help of Streamlit Module in Python. Required Modules: For this, we will need Three Modules. StreamlitTextBlobStreamlit_extras (optional). The module Streamlit_extras is optional because it will be used to add some extra features which will not affect th
4 min read
How to Create a Simple Messagebox in Python
Python has the capability to create GUI applications using libraries like tkinter and PyQt5. These libraries provide easy-to-use methods for creating various GUI elements, including messageboxes. In this article, we will explore both this approaches to create a simple messagebox in Python. Create A Simple Messagebox In PythonBelow are the possible
2 min read
Create simple Blockchain using Python
Blockchain is a time-stamped decentralized series of fixed records that contains data of any size is controlled by a large network of computers that are scattered around the globe and not owned by a single organization. Every block is secured and connected with each other using hashing technology which protects it from being tampered by an unauthor
8 min read
Create a Python Script Notifying to take a break
We generally do not take breaks when we are using our laptop or PC. It might affect our eyesight as well as mind. So with Python, we can make a program that can notify us that we have to take a break start again after sometime when the user again starts working on the laptop. Modules neededpyttsx3 - It is a text-to-speech conversion library in Pyth
4 min read
Python Script to create random jokes using pyjokes
Python supports creation of random jokes using one of its libraries. Let us explore it a little more, Pyjokes is a python library that is used to create one-line jokes for programmers. Informally, it can also be referred as a fun python library which is pretty simple to use. Let us see how you can actually use it to perform the required task, Insta
2 min read
Simple registration form using Python Tkinter
Prerequisites: Tkinter Introduction, openpyxl module.Python provides the Tkinter toolkit to develop GUI applications. Now, it’s upto the imagination or necessity of developer, what he/she want to develop using this toolkit. Let's make a simple information form GUI application using Tkinter. In this application, User has to fill up the required info
5 min read
Python | Simple GUI calculator using Tkinter
Prerequisite: Tkinter Introduction, lambda function Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI a
6 min read
Python | Program to implement simple FLAMES game
Python is a multipurpose language and one can do literally anything with it. Python can also be used for game development. Let’s create a simple FLAMES game without using any external game libraries like PyGame. FLAMES is a popular game named after the acronym: Friends, Lovers, Affectionate, Marriage, Enemies, Sibling. This game does not accurately
6 min read
Python | Simple FLAMES game using Tkinter
Prerequisites: Introduction to TkinterProgram to implement simple FLAMES game Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and e
5 min read
How to Build a Simple Android App with Flask Backend?
Flask is an API of Python that allows us to build up web applications. It was developed by Armin Ronacher. Flask’s framework is more explicit than Django’s framework and is also easier to learn because it has less base code to implement a simple web-Application. A Web-Application Framework or Web Framework is the collection of modules and libraries
8 min read
Python | Simple calculator using Tkinter
Prerequisite : Tkinter IntroductionPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest way to create the GUI applications. Cr
3 min read
Article Tags :
Practice Tags :