SlideShare a Scribd company logo
Basic terms that we know
 Web Application
• A Web application (Web app) is an application
program that is stored on a remote server and
delivered over the Internet through a browser
interface.
 Web Server
• A web server is a computer system that processes
requests via HTTP, the basic network protocol
used to distribute information on the World Wide
Web.
 Web Browser
• A web browser is a software application for
retrieving, presenting and traversing
information resources on the World Wide Web.
 HTML
• HyperText Markup Language (HTML) is the
standard markup language for creating web
pages and web applications.
 Static Pages
• static Web pages are those with content that
cannot change without a developer editing its
source code,
 Dynamic Pages
• while dynamic Web pages can display different
content from the same source code.
What is HTTP?
 HTTP (Hypertext Transfer Protocol) is the set of rules
for transferring files (text, graphic images, sound,
video, and other multimedia files) on the World Wide
Web.
 As soon as a Web user opens their Web browser, the user
is indirectly making use of HTTP.
 HTTP is an application protocol that runs on top of the
TCP/IP suite of protocols (the foundation protocols for the
Internet).
 TCP/IP (Transmission Control Protocol/Internet Protocol) is
the basic communication language or protocol of the
Internet. It can also be used as a communications protocol
in a private network (either an intranet or an extranet).
Get & Post Methods
 It specifies how to send the form data
to a web server.
 The data can be sent as URL
variables, by using the get (default)
method or as HTTP post, by using post
method.
Get method
 Get sends the data as part of the URL.
 Appends form-data into the URL in name/value pairs.
 The length of a URL is limited 2048 characters.
 Never use GET method if you have password or other sensitive
information to be sent to the server.
 Get is better for non secure data. Like query string in Google
(https://www.google.co.in/?
gfe_rd=cr&ei=KJWNWJ_lKKnT8ge0gYjQBw#safe=strict&q=what+i
s+php)
 Get can’t be used to send binary data. Ex. Images or word
documents.
 <form action=“myform.php” method=“GET”/>
Post Method
 http post requests supply additional data form the client (browser)
to the server in the message body.
 Appends form-data inside the body of the HTTP request (data is not
shown is in URL)
 Don’t have any restriction on data size to be sent.
 Post can not be bookmarked.
 Used to send ASCII as well as binary data. (img, word document)
 Is safe because the parameters are not stored in browser history or
in the web server logs.
 <from action=“some.php” method=“post”/>
What is CGI?
Web Browsing
 To understand the concept of CGI, let us see what happens
when we click a hyper link to browse a particular web page
or URL.
 Your browser contacts the HTTP web server and
demands for the URL, i.e., filename.
 Web Server parses the URL and looks for the filename.
 If it finds that file then sends it back to the browser,
otherwise sends an error message indicating that you
requested a wrong file.
 Web browser takes response from web server and displays
either the received file or error message.
What is CGI?
 However, it is possible to set up the HTTP server so that
whenever a file in a certain directory is requested that
file is not sent back;
 instead it is executed as a program, and whatever that
program outputs is sent back for your browser to display.
 This function is called the Common Gateway Interface or
CGI and the programs are called CGI scripts.
 CGI standard defines server-program interaction
• Developed at the National Center for Supercomputing Applications
(NCSA)
 􀂄 CGI was the first way of generating dynamic content.
 These CGI programs can be a Python Script, PERL
Script, Shell Script, C or C++ program, etc.
WWW
Client
CGI
program
WWW
Server
request
response
Invoke CGI
CGI output
internet server
How to Run Python on
XAMPP web server
 you have installed both xampp and
python on the C Drive:
 c:/xampp
 c:/python27 or c:/python35
Running Python Scripts via
CGI
 Modify http.conf
 Locate the configuration file http.conf in
c:xamppapacheconfhttpd.conf.
 In http.conf look for this line: AddHandler cgi-script
.cgi .pl .asp.
 Modify it so it looks like this: AddHandler cgi-script .cgi .pl
.asp .py
 You probably won't need to do this, but just to be sure, look
for this line: Options Indexes FollowSymLinks.
 Ensure that it looks like this: Options Indexes
FollowSymLinks Includes ExecCGI
 Restart Apache
 At the top of each Python script you create,
set the path to your version of Python.
 For instance, ours is in C:Python27 so we
write: #!/Python27/python
 Example script, create folder
at C:xampphtdocs and create script file
with .cgi extension containing the following
code within the folder:-
Simple CGI Application
#!/Python27/python.exe
print "Content-type:text/htmlrnrn"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI
program</h2>'
print '</body>'
print '</html>'
How to process html form data
with Python
 Create a file named "process_form" with the
code below and save it in a file with .py or
.cgi extension at this location
"C:xampphtdocscgirj" where the html form
file (myForm.html) above is located.
 Edit the html form "action" attribute to point to
the (cgi or py) python file above
(process_form.cgi).
CGI module
 There is one primary class in the cgi module that does all
the work: the FieldStorage class.
 This class should be instantiated when a Python CGI script
begins, as it will read in all the pertinent user information
from the Web client (via the Web server).
 Once this object has been instantiated, it will consist of a
dictionary-like object that has a set of key-value pairs.
 The keys are the names of the form items that were
passed in through the form while the values contain the
corresponding data.
 These values themselves can be one of three objects.
 They can be FieldStorage objects (instances) as well as
instances of a similar class called MiniFieldStorage, which
is used in cases where no file uploads or multiple-part form
data is involved.
 MiniFieldStorage instances contain only the key-value pair
of the name and the data. Lastly, they can be a list of such
objects.
 This occurs when a form contains more than one input item
with the same field name.
Cgitb module
 The cgitb module provides a special exception handler for Python
scripts. (Its name is a bit misleading. It was originally designed to display
extensive traceback information in HTML for CGI scripts. It was later
generalized to also display this information in plain text.)
 After this module is activated, if an uncaught exception occurs, a
detailed, formatted report will be displayed.
 The report includes a traceback showing excerpts of the source code for
each level, as well as the values of the arguments and local variables to
currently running functions, to help you debug the problem.
 Optionally, you can save this information to a file instead of sending it to
the browser.
 To enable this feature, simply add this to the top of your CGI script:
 import cgitb
 cgitb.enable()
Field storage
 To access the data submitted by the form in our script we
will need to make use of the FieldStorage() function
available in the cgi module of Python.
 For example, we would assign the data from the form to a
Python variable in the following way:
 formData = cgi.FieldStorage()
 The variable formData now contains every piece of
data submitted by the form.
 Other tool that provide Apache web
server on PC are WAMP or AMPPS.
 AMPPS is a stack of Apache, MySQL,
MongoDB, PHP, Perl & Python.
CGI: Pros and Cons
 Pros of CGI:
• Simple; suitable for small once-off tasks
• Supported by all web servers
 Cons of CGI:
• Slow; web server forks new process for every
request
• Parameter decoding tedious
Advanced CGI
Multi part form submission,
File upload,
Cookies
Cookie
 Cookies are basically key-value pairs
that a web server can set for a client's
web browser.
 This lets server programs track what
pages a user has visited or what actions
the user has performed. Cookies are
very useful for implementing things like
log-in sessions or shopping carts.
Using Cookies in CGI
 HTTP protocol is a stateless protocol. For a commercial
website, it is required to maintain session information among
different pages.
 For example, one user registration ends after completing
many pages. How to maintain user's session information
across all the web pages?
 In many situations, using cookies is the most efficient
method of remembering and tracking preferences,
purchases, commissions, and other information required for
better visitor experience or site statistics.
How It Works?
 Your server sends some data to the visitor's browser in the
form of a cookie.
 The browser may accept the cookie.
 If it does, it is stored as a plain text record on the visitor's
hard drive.
 Now, when the visitor arrives at another page on your site,
the cookie is available for retrieval. Once retrieved, your
server knows/remembers what was stored.
 The HTTP headers are a series of text parameters sparated
by carriage return and line feed characters.
 Cookies are set using the Set-Cookie parameter.
 Cookies are a plain text data record of 5 variable-length fields:
 Expires: The date the cookie will expire. If this is blank, the cookie will
expire when the visitor quits the browser.
 Domain: The domain name of your site.
 Path: The path to the directory or web page that sets the cookie. This
may be blank if you want to retrieve the cookie from any directory or
page.
 Secure: If this field contains the word "secure", then the cookie may
only be retrieved with a secure server. If this field is blank, no such
restriction exists.
 Name=Value: Cookies are set and retrieved in the form of key and
value pairs.
Setting up Cookies
 It is very easy to send cookies to browser.
 These cookies are sent along with HTTP
Header before to Content-type field.
 Assuming you want to set UserID and
Password as cookies.
File Upload Example
 To upload a file, the HTML form must
have the enctype attribute set to
multipart/form-data.
 The input tag with the file type creates a
"Browse" button.
CGI by rj

More Related Content

What's hot

ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
Ido Flatow
 
0 csc 3311 slide internet programming
0 csc 3311 slide internet programming0 csc 3311 slide internet programming
0 csc 3311 slide internet programming
umardanjumamaiwada
 
Lecture 6- http
Lecture  6- httpLecture  6- http
Lecture 6- http
Saman M. Almufti
 
What's up with HTTP?
What's up with HTTP?What's up with HTTP?
What's up with HTTP?
Mark Nottingham
 
Http
HttpHttp
Html intake 38 lect1
Html intake 38 lect1Html intake 38 lect1
Html intake 38 lect1
ghkadous
 
Www and http
Www and httpWww and http
Www and http
SanthiNivas
 
Http-protocol
Http-protocolHttp-protocol
Http-protocol
Toushik Paul
 
Http protocol
Http protocolHttp protocol
Http protocol
Arpita Naik
 
HTTP
HTTPHTTP
Http headers
Http headersHttp headers
Http headers
Judy Ngure
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
Kevin Hazzard
 
SCWCD : The web client model
SCWCD : The web client modelSCWCD : The web client model
SCWCD : The web client model
Ben Abdallah Helmi
 
Hypertext transfer protocol (http)
Hypertext transfer protocol (http)Hypertext transfer protocol (http)
Hypertext transfer protocol (http)johnny19910916
 
Hypertex transfer protocol
Hypertex transfer protocolHypertex transfer protocol
Hypertex transfer protocolwanangwa234
 
HTTP Protocol Basic
HTTP Protocol BasicHTTP Protocol Basic
HTTP Protocol Basic
Chuong Mai
 
Overview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB APIOverview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB API
Pankaj Bajaj
 
SCWCD : The web client model : CHAP : 1
SCWCD  : The web client model : CHAP : 1SCWCD  : The web client model : CHAP : 1
SCWCD : The web client model : CHAP : 1
Ben Abdallah Helmi
 
HTTP
HTTPHTTP

What's hot (20)

ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
0 csc 3311 slide internet programming
0 csc 3311 slide internet programming0 csc 3311 slide internet programming
0 csc 3311 slide internet programming
 
Lecture 6- http
Lecture  6- httpLecture  6- http
Lecture 6- http
 
What's up with HTTP?
What's up with HTTP?What's up with HTTP?
What's up with HTTP?
 
Http
HttpHttp
Http
 
Html intake 38 lect1
Html intake 38 lect1Html intake 38 lect1
Html intake 38 lect1
 
Www and http
Www and httpWww and http
Www and http
 
Http-protocol
Http-protocolHttp-protocol
Http-protocol
 
Http protocol
Http protocolHttp protocol
Http protocol
 
HTTP
HTTPHTTP
HTTP
 
Http headers
Http headersHttp headers
Http headers
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
 
SCWCD : The web client model
SCWCD : The web client modelSCWCD : The web client model
SCWCD : The web client model
 
Hypertext transfer protocol (http)
Hypertext transfer protocol (http)Hypertext transfer protocol (http)
Hypertext transfer protocol (http)
 
Hypertex transfer protocol
Hypertex transfer protocolHypertex transfer protocol
Hypertex transfer protocol
 
HTTP Protocol Basic
HTTP Protocol BasicHTTP Protocol Basic
HTTP Protocol Basic
 
Overview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB APIOverview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB API
 
Introduction About PHP
 Introduction About PHP Introduction About PHP
Introduction About PHP
 
SCWCD : The web client model : CHAP : 1
SCWCD  : The web client model : CHAP : 1SCWCD  : The web client model : CHAP : 1
SCWCD : The web client model : CHAP : 1
 
HTTP
HTTPHTTP
HTTP
 

Similar to CGI by rj

contentDM
contentDMcontentDM
contentDM
spacecowboyian
 
Slides serverside main
Slides serverside mainSlides serverside main
Slides serverside main
ggunasagar
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
Sasidhar Kothuru
 
CGI Presentation
CGI PresentationCGI Presentation
CGI Presentation
Sopan Shewale
 
Introduction to back-end
Introduction to back-endIntroduction to back-end
Introduction to back-end
Mosaab Ehab
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009Cathie101
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009Cathie101
 
web services8 (1).pdf for computer science
web services8 (1).pdf for computer scienceweb services8 (1).pdf for computer science
web services8 (1).pdf for computer science
optimusnotch44
 
15.web document types.pdf bdgjrjdhdhsgbdidh
15.web document types.pdf bdgjrjdhdhsgbdidh15.web document types.pdf bdgjrjdhdhsgbdidh
15.web document types.pdf bdgjrjdhdhsgbdidh
KomaliGuptha1
 
Common gateway interface
Common gateway interfaceCommon gateway interface
Common gateway interfaceAnandita
 
How cgi scripting works
How cgi scripting worksHow cgi scripting works
How cgi scripting works
RaxTonProduction
 
Web engineering 2(lect 2)
Web engineering 2(lect 2)Web engineering 2(lect 2)
Web engineering 2(lect 2)
Roohul Amin
 
Configuring the Apache Web Server
Configuring the Apache Web ServerConfiguring the Apache Web Server
Configuring the Apache Web Serverwebhostingguy
 
21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMSkoolkampus
 

Similar to CGI by rj (20)

Python cgi programming
Python cgi programmingPython cgi programming
Python cgi programming
 
Cgi
CgiCgi
Cgi
 
contentDM
contentDMcontentDM
contentDM
 
Fm 2
Fm 2Fm 2
Fm 2
 
Slides serverside main
Slides serverside mainSlides serverside main
Slides serverside main
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
CGI Presentation
CGI PresentationCGI Presentation
CGI Presentation
 
Introduction to back-end
Introduction to back-endIntroduction to back-end
Introduction to back-end
 
Copy of cgi
Copy of cgiCopy of cgi
Copy of cgi
 
Cgi
CgiCgi
Cgi
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
 
Common Gateway Interface
Common Gateway InterfaceCommon Gateway Interface
Common Gateway Interface
 
web services8 (1).pdf for computer science
web services8 (1).pdf for computer scienceweb services8 (1).pdf for computer science
web services8 (1).pdf for computer science
 
15.web document types.pdf bdgjrjdhdhsgbdidh
15.web document types.pdf bdgjrjdhdhsgbdidh15.web document types.pdf bdgjrjdhdhsgbdidh
15.web document types.pdf bdgjrjdhdhsgbdidh
 
Common gateway interface
Common gateway interfaceCommon gateway interface
Common gateway interface
 
How cgi scripting works
How cgi scripting worksHow cgi scripting works
How cgi scripting works
 
Web engineering 2(lect 2)
Web engineering 2(lect 2)Web engineering 2(lect 2)
Web engineering 2(lect 2)
 
Configuring the Apache Web Server
Configuring the Apache Web ServerConfiguring the Apache Web Server
Configuring the Apache Web Server
 
21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS21. Application Development and Administration in DBMS
21. Application Development and Administration in DBMS
 

More from Shree M.L.Kakadiya MCA mahila college, Amreli

Machine Learning by Rj
Machine Learning by RjMachine Learning by Rj
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Servlet unit 2
Servlet unit 2 Servlet unit 2
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Motion capture by Rj
Motion capture by RjMotion capture by Rj
Research paper on big data and hadoop
Research paper on big data and hadoopResearch paper on big data and hadoop
Research paper on big data and hadoop
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Text processing by Rj
Text processing by RjText processing by Rj
Python and data analytics
Python and data analyticsPython and data analytics
Multithreading by rj
Multithreading by rjMultithreading by rj
Database programming
Database programmingDatabase programming
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Seminar on Project Management by Rj
Seminar on Project Management by RjSeminar on Project Management by Rj
Seminar on Project Management by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Spring by rj
Spring by rjSpring by rj
Python by Rj
Python by RjPython by Rj
Leadership & Motivation
Leadership & MotivationLeadership & Motivation
Event handling
Event handlingEvent handling

More from Shree M.L.Kakadiya MCA mahila college, Amreli (20)

Machine Learning by Rj
Machine Learning by RjMachine Learning by Rj
Machine Learning by Rj
 
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
 
Servlet unit 2
Servlet unit 2 Servlet unit 2
Servlet unit 2
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Motion capture by Rj
Motion capture by RjMotion capture by Rj
Motion capture by Rj
 
Research paper on big data and hadoop
Research paper on big data and hadoopResearch paper on big data and hadoop
Research paper on big data and hadoop
 
Text processing by Rj
Text processing by RjText processing by Rj
Text processing by Rj
 
Python and data analytics
Python and data analyticsPython and data analytics
Python and data analytics
 
Multithreading by rj
Multithreading by rjMultithreading by rj
Multithreading by rj
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Database programming
Database programmingDatabase programming
Database programming
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Seminar on Project Management by Rj
Seminar on Project Management by RjSeminar on Project Management by Rj
Seminar on Project Management by Rj
 
Spring by rj
Spring by rjSpring by rj
Spring by rj
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
Leadership & Motivation
Leadership & MotivationLeadership & Motivation
Leadership & Motivation
 
Event handling
Event handlingEvent handling
Event handling
 

Recently uploaded

PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

CGI by rj

  • 1. Basic terms that we know  Web Application • A Web application (Web app) is an application program that is stored on a remote server and delivered over the Internet through a browser interface.  Web Server • A web server is a computer system that processes requests via HTTP, the basic network protocol used to distribute information on the World Wide Web.
  • 2.  Web Browser • A web browser is a software application for retrieving, presenting and traversing information resources on the World Wide Web.  HTML • HyperText Markup Language (HTML) is the standard markup language for creating web pages and web applications.
  • 3.  Static Pages • static Web pages are those with content that cannot change without a developer editing its source code,  Dynamic Pages • while dynamic Web pages can display different content from the same source code.
  • 4. What is HTTP?  HTTP (Hypertext Transfer Protocol) is the set of rules for transferring files (text, graphic images, sound, video, and other multimedia files) on the World Wide Web.  As soon as a Web user opens their Web browser, the user is indirectly making use of HTTP.  HTTP is an application protocol that runs on top of the TCP/IP suite of protocols (the foundation protocols for the Internet).  TCP/IP (Transmission Control Protocol/Internet Protocol) is the basic communication language or protocol of the Internet. It can also be used as a communications protocol in a private network (either an intranet or an extranet).
  • 5.
  • 6. Get & Post Methods  It specifies how to send the form data to a web server.  The data can be sent as URL variables, by using the get (default) method or as HTTP post, by using post method.
  • 7. Get method  Get sends the data as part of the URL.  Appends form-data into the URL in name/value pairs.  The length of a URL is limited 2048 characters.  Never use GET method if you have password or other sensitive information to be sent to the server.  Get is better for non secure data. Like query string in Google (https://www.google.co.in/? gfe_rd=cr&ei=KJWNWJ_lKKnT8ge0gYjQBw#safe=strict&q=what+i s+php)  Get can’t be used to send binary data. Ex. Images or word documents.  <form action=“myform.php” method=“GET”/>
  • 8. Post Method  http post requests supply additional data form the client (browser) to the server in the message body.  Appends form-data inside the body of the HTTP request (data is not shown is in URL)  Don’t have any restriction on data size to be sent.  Post can not be bookmarked.  Used to send ASCII as well as binary data. (img, word document)  Is safe because the parameters are not stored in browser history or in the web server logs.  <from action=“some.php” method=“post”/>
  • 9.
  • 10. What is CGI? Web Browsing  To understand the concept of CGI, let us see what happens when we click a hyper link to browse a particular web page or URL.  Your browser contacts the HTTP web server and demands for the URL, i.e., filename.  Web Server parses the URL and looks for the filename.  If it finds that file then sends it back to the browser, otherwise sends an error message indicating that you requested a wrong file.  Web browser takes response from web server and displays either the received file or error message.
  • 11. What is CGI?  However, it is possible to set up the HTTP server so that whenever a file in a certain directory is requested that file is not sent back;  instead it is executed as a program, and whatever that program outputs is sent back for your browser to display.  This function is called the Common Gateway Interface or CGI and the programs are called CGI scripts.  CGI standard defines server-program interaction • Developed at the National Center for Supercomputing Applications (NCSA)  􀂄 CGI was the first way of generating dynamic content.  These CGI programs can be a Python Script, PERL Script, Shell Script, C or C++ program, etc.
  • 12.
  • 14. How to Run Python on XAMPP web server  you have installed both xampp and python on the C Drive:  c:/xampp  c:/python27 or c:/python35
  • 15. Running Python Scripts via CGI  Modify http.conf  Locate the configuration file http.conf in c:xamppapacheconfhttpd.conf.  In http.conf look for this line: AddHandler cgi-script .cgi .pl .asp.  Modify it so it looks like this: AddHandler cgi-script .cgi .pl .asp .py  You probably won't need to do this, but just to be sure, look for this line: Options Indexes FollowSymLinks.  Ensure that it looks like this: Options Indexes FollowSymLinks Includes ExecCGI  Restart Apache
  • 16.  At the top of each Python script you create, set the path to your version of Python.  For instance, ours is in C:Python27 so we write: #!/Python27/python  Example script, create folder at C:xampphtdocs and create script file with .cgi extension containing the following code within the folder:-
  • 17. Simple CGI Application #!/Python27/python.exe print "Content-type:text/htmlrnrn" print '<html>' print '<head>' print '<title>Hello Word - First CGI Program</title>' print '</head>' print '<body>' print '<h2>Hello Word! This is my first CGI program</h2>' print '</body>' print '</html>'
  • 18. How to process html form data with Python  Create a file named "process_form" with the code below and save it in a file with .py or .cgi extension at this location "C:xampphtdocscgirj" where the html form file (myForm.html) above is located.  Edit the html form "action" attribute to point to the (cgi or py) python file above (process_form.cgi).
  • 19. CGI module  There is one primary class in the cgi module that does all the work: the FieldStorage class.  This class should be instantiated when a Python CGI script begins, as it will read in all the pertinent user information from the Web client (via the Web server).  Once this object has been instantiated, it will consist of a dictionary-like object that has a set of key-value pairs.  The keys are the names of the form items that were passed in through the form while the values contain the corresponding data.
  • 20.  These values themselves can be one of three objects.  They can be FieldStorage objects (instances) as well as instances of a similar class called MiniFieldStorage, which is used in cases where no file uploads or multiple-part form data is involved.  MiniFieldStorage instances contain only the key-value pair of the name and the data. Lastly, they can be a list of such objects.  This occurs when a form contains more than one input item with the same field name.
  • 21. Cgitb module  The cgitb module provides a special exception handler for Python scripts. (Its name is a bit misleading. It was originally designed to display extensive traceback information in HTML for CGI scripts. It was later generalized to also display this information in plain text.)  After this module is activated, if an uncaught exception occurs, a detailed, formatted report will be displayed.  The report includes a traceback showing excerpts of the source code for each level, as well as the values of the arguments and local variables to currently running functions, to help you debug the problem.  Optionally, you can save this information to a file instead of sending it to the browser.  To enable this feature, simply add this to the top of your CGI script:  import cgitb  cgitb.enable()
  • 22. Field storage  To access the data submitted by the form in our script we will need to make use of the FieldStorage() function available in the cgi module of Python.  For example, we would assign the data from the form to a Python variable in the following way:  formData = cgi.FieldStorage()  The variable formData now contains every piece of data submitted by the form.
  • 23.  Other tool that provide Apache web server on PC are WAMP or AMPPS.  AMPPS is a stack of Apache, MySQL, MongoDB, PHP, Perl & Python.
  • 24. CGI: Pros and Cons  Pros of CGI: • Simple; suitable for small once-off tasks • Supported by all web servers  Cons of CGI: • Slow; web server forks new process for every request • Parameter decoding tedious
  • 25. Advanced CGI Multi part form submission, File upload, Cookies
  • 26. Cookie  Cookies are basically key-value pairs that a web server can set for a client's web browser.  This lets server programs track what pages a user has visited or what actions the user has performed. Cookies are very useful for implementing things like log-in sessions or shopping carts.
  • 27. Using Cookies in CGI  HTTP protocol is a stateless protocol. For a commercial website, it is required to maintain session information among different pages.  For example, one user registration ends after completing many pages. How to maintain user's session information across all the web pages?  In many situations, using cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics.
  • 28. How It Works?  Your server sends some data to the visitor's browser in the form of a cookie.  The browser may accept the cookie.  If it does, it is stored as a plain text record on the visitor's hard drive.  Now, when the visitor arrives at another page on your site, the cookie is available for retrieval. Once retrieved, your server knows/remembers what was stored.  The HTTP headers are a series of text parameters sparated by carriage return and line feed characters.  Cookies are set using the Set-Cookie parameter.
  • 29.  Cookies are a plain text data record of 5 variable-length fields:  Expires: The date the cookie will expire. If this is blank, the cookie will expire when the visitor quits the browser.  Domain: The domain name of your site.  Path: The path to the directory or web page that sets the cookie. This may be blank if you want to retrieve the cookie from any directory or page.  Secure: If this field contains the word "secure", then the cookie may only be retrieved with a secure server. If this field is blank, no such restriction exists.  Name=Value: Cookies are set and retrieved in the form of key and value pairs.
  • 30. Setting up Cookies  It is very easy to send cookies to browser.  These cookies are sent along with HTTP Header before to Content-type field.  Assuming you want to set UserID and Password as cookies.
  • 31. File Upload Example  To upload a file, the HTML form must have the enctype attribute set to multipart/form-data.  The input tag with the file type creates a "Browse" button.