0% found this document useful (0 votes)
4 views

Python Chapter16 CGI.pptx

The document provides an overview of the Common Gateway Interface (CGI), detailing its role in facilitating communication between web servers and scripts. It explains the configuration requirements for CGI on web servers, including directory settings and script execution. Additionally, it includes a simple example of a CGI program written in Python, demonstrating how to output HTML content to a web browser.

Uploaded by

adarshhalse45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Chapter16 CGI.pptx

The document provides an overview of the Common Gateway Interface (CGI), detailing its role in facilitating communication between web servers and scripts. It explains the configuration requirements for CGI on web servers, including directory settings and script execution. Additionally, it includes a simple example of a CGI program written in Python, demonstrating how to output HTML content to a web browser.

Uploaded by

adarshhalse45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Training

CGI
by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm The Common Gateway Interface, or CGI, is a set of
a standards that define how information is
+91-
9928016
exchanged between the web server and a custom
d y
573

the NCSA. t u
script. The CGI specs are currently maintained by

What is CGI? S
D
The Common Gateway Interface, or CGI, is a

J M
standard for external gateway programs to
interface with information servers such as HTTP
servers.
The current version is CGI/1.1 and CGI/1.2 is under
progress.
MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 1
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance Web Browsing


by
Yogan
JMD Study Computer Classes
and
Sharm To understand the concept of CGI, let us see what
a happens when we click a hyper link to browse a
+91-
9928016
particular web page or URL.
d y
573

demands for the URL, i.e., filename.t u


Your browser contacts the HTTP web server and

S
Web Server parses the URL and looks for the
D
filename. If it finds that file then sends it back to the

J M
browser, otherwise sends an error message
indicating that you requested a wrong file.

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA,
MCA Notes
Internship. 2
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

Web Browsing
by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm Web browser takes response from web server and
a displays either the received file or error message.
+91-
9928016
d y
However, it is possible to set up the HTTP server so
573
t u
that whenever a file in a certain directory is
requested that file is not sent back; instead it is
S
executed as a program, and whatever that
D
program outputs is sent back for your browser to
display.
J M
This function is called the Common Gateway
Interface or CGI and the programs are called CGI
scripts. These CGI programs can be a Python Script,
PERL Script, Shell Script, C or C++ program, etc.
MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 3
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance CGI Architecture Diagram


by
Yogan
JMD Study Computer Classes
and
Sharm
a
+91-
9928016
d y
573
t u
S
D
J M
a

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA,
MCA Notes
Internship. 4
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Web Server Support and Configuration
JMD Study Computer Classes
and
Sharm Before you proceed with CGI Programming, make sure
a
that your Web Server supports CGI and it is configured
+91-
9928016 executed by the HTTP server are kept in a pre-
d y
to handle CGI Programs. All the CGI Programs to be
573
t u
configured directory. This directory is called CGI
Directory and by convention it is named as
S
/var/www/cgi-bin. By convention, CGI files have
extension as. cgi, but you can keep your files with
python extension .py as well.D
J M
By default, the Linux server is configured to run only the
scripts in the cgi-bin directory in /var/www. If you want
to specify any other directory to run your CGI scripts,
comment the following lines in the httpd.conf file −
<Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
like Perl or Shell, etc.
MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 5
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan
Web Server Support and Configuration
JMD Study Computer Classes
and
Sharm Order allow,deny
a Allow from all
+91-
9928016
</Directory>
d y
573 <Directory "/var/www/cgi-bin">
Options All t u
</Directory> S
D
Here, we assume that you have Web Server up and

J M
running successfully and you are able to run any
other CGI program like Perl or Shell, etc.

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA,
MCA Notes
Internship. 6
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

First CGI Program


by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and Here is a simple link, which is linked to a CGI script called
Sharm
a
hello.py. This file is kept in /var/www/cgi-bin directory
+91-
9928016
d
program, make sure you have change mode of file
y
and it has following content. Before running your CGI
573
t u
using chmod 755 hello.py UNIX command to make file
executable.
#!/usr/bin/python
S
D
print ("Content-type:text/html\r\n\r\n")
print ('<html>')
print ('<head>') J M
print ('<title>Hello Word - First CGI Program</title>')
print ('</head>')
print ('<body>')

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 7
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance First CGI Program


by
Yogan
JMD Study Computer Classes
and print ('<h2>Hello Word! This is my first CGI
Sharm
a program</h2>')
+91-
9928016
print ('</body>')
print ('</html>') d y
573
t u
Note − First line in the script must be path to Python
S
executable. In Linux it should be #!/usr/bin/python3
D
Enter following URL in yor browser
M
http://localhost:8080/cgi-bin/hello.py
J

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA,
MCA Notes
Internship. 8
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

First CGI Program


by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and Hello Word! This is my first CGI program
Sharm
a This hello.py script is a simple Python script, which
+91-
9928016
d y
writes its output on STDOUT file, i.e., screen. There
is one important and extra feature available which
573
is first line to be printed Content-
t u
S
type:text/html\r\n\r\n. This line is sent back to the
browser and it specifies the content type to be
D
displayed on the browser screen.

J M
By now you must have understood basic concept of
CGI and you can write many complicated CGI
programs using Python. This script can interact with
any other external system also to exchange
information such as RDBMS.

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 9
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance HTTP Header


by
Yogan
JMD Study Computer Classes
and
Sharm The line Content-type:text/html\r\n\r\n is part of HTTP
a
header which is sent to the browser to understand the
+91-
9928016 form −
d y
content. All the HTTP header will be in the following
573 HTTP Field Name: Field Content
For Example t u
Content-type: text/html\r\n\r\n
S
There are few other important HTTP headers, which
D
you will use frequently in your CGI Programming.
1
Content-type: J M
Sr.No. Header & Description

A MIME string defining the format of the file being


returned. Example is Content-type:text/html

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 10
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

HTTP Header
by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
2
Sharm Expires: Date
a The date the information becomes invalid. It is used by the
+91-
9928016
d y
browser to decide when a page needs to be refreshed. A valid date
string is in the format 01 Jan 1998 12:00:00 GMT.
573 3
Location: URL
t u
S
The URL that is returned instead of the URL requested. You can
use this field to redirect a request to any file.
4
Last-modified: Date D
M
The date of last modification of the resource.

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 11
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance HTTP Header


by
Yogan
JMD Study Computer Classes
and
Sharm 5
a Content-length: N
+91-
9928016
d y
The length, in bytes, of the data being returned. The
573

download time for a file. t u


browser uses this value to report the estimated

6 S
Set-Cookie: String D
M
Set the cookie passed through the string
J

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 12
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

CGI Environment Variables


by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
All the CGI programs have access to the following environment
Sharm variables. These variables play an important role while writing any
a CGI program.
+91-
9928016
Sr.No. Variable Name & Description
1
d y
573 CONTENT_TYPE
t u
The data type of the content. Used when the client is sending
S
attached content to the server. For example, file upload.
2
CONTENT_LENGTH
D
The length of the query information. It is available only for POST
requests.

J M

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 13
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance CGI Environment Variables


by
Yogan
JMD Study Computer Classes
and
3
Sharm HTTP_COOKIE
a
+91-
9928016
4
HTTP_USER_AGENT d y
Returns the set cookies in the form of key & value pair.

573
t u
The User-Agent request-header field contains information

S
about the user agent originating the request. It is name of
the web browser.
5
PATH_INFO D
M
The path for the CGI script.
J

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 14
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

CGI Environment Variables


by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm 6. QUERY_STRING
a
+91-
9928016
The URL-encoded information that is sent with GET
method request.
d y
573
7. REMOTE_ADDR t u
S
The IP address of the remote host making the request.
D
This is useful logging or for authentication.
8. REMOTE_HOST
J M
The fully qualified name of the host making the request.
If this information is not available, then REMOTE_ADDR
can be used to get IR address.

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 15
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance CGI Environment Variables


by
Yogan
JMD Study Computer Classes
and
9
Sharm REQUEST_METHOD
a
+91-
9928016
methods are GET and POST.
10 d y
The method used to make the request. The most common

573
SCRIPT_FILENAME
t u
The full path to the CGI script.
11 S
SCRIPT_NAME
The name of the CGI script. D
J M

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 16
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

CGI Environment Variables


by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm 12
a SERVER_NAME
+91-
9928016
The server's hostname or IP Address
d y
573 13
SERVER_SOFTWARE t u
S
The name and version of the software the server is
running. D
J M

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCABCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/MCA/
M.Tech/ B.Tech/
M.Tech/ BCA Intenship/
B.Tech/ Industrial/
BCA Internship/ Live Project
Industrial/ Live Training.
Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 17
Project Training
Designing, Digital
in Python, Android,
Marketing, SEO,
PHP,
SMO,
ASP.NET,
C, C++.
C++. Call:
Machine Learning, SQL, JAVA,
Web Designing,
Web Designing, Digital
Digital Marketing,
Marketing, SEO,
SEO, SMO,
SMO, C, Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance GET and POST Methods


by
Yogan
JMD Study Computer Classes
and
Sharm You must have come across many situations when
a you need to pass some information from your
+91-
9928016
d y
browser to web server and ultimately to your CGI
573
t u
Program. Most frequently, browser uses two
methods two pass this information to web server.
S
These methods are GET Method and POST
Method. D
J M

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 18
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Passing Information using GET
JMD Study Computer Classes
and
Sharm method
The GET method has size limtation: only 1024
a characters can be sent in a request string.
+91-
9928016
The GET method sends information using
QUERY_STRING header and will be accessible in d y
573
your CGI Program through QUERY_STRING t u
environment variable. S
You can pass information by simply concatenating
D
key and value pairs along with any URL or you can

GET method. J M
use HTML <FORM> tags to pass information using

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 19
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan Passing Information using GET
JMD Study Computer Classes
and
Sharm method
The GET method sends the encoded user information
a appended to the page request. The page and the
+91-
9928016 as follows − d y
encoded information are separated by the ? character
573
t
http://www.test.com/cgi-bin/hello.py? u
key1=value1&key2=value2
S
The GET method is the default method to pass
D
information from the browser to the web server and it

Location:box.
J M
produces a long string that appears in your browser's

Never use GET method if you have password or other


sensitive information to pass to the server.

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 20
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Simple URL Example:Get Method
JMD Study Computer Classes
and
Here is a simple URL, which passes two values to hello_get.py
Sharm program using GET method.
a
+91-
9928016
y
/cgi-bin/hello_get.py?first_name=ZARA&last_name=ALI
Below is hello_get.py script to handle input given by web
d
browser. We are going to use cgi module, which makes it
573
t
very easy to access passed information −u
# Import modules for CGI handling
import cgi, cgitb S
D
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
J M
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project Training
Training in Python,
in Python, Android,
Android, PHP, ASP.NET,
PHP, ASP.NET, Machine Learning,
Python Notes
Machine Learning, SQL, SQL, JAVA, 21
JAVA, Web
Designing,
Web Designing, DigitalMarketing,
Digital Marketing, SEO,
SEO,SMO, C, C++.
SMO, Call: 9928016573,
C, C++. 9887116583
Call: 9649141215, www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan Simple URL Example:Get Method
JMD Study Computer Classes
and
Sharm print ("Content-type:text/html\r\n\r\n")
a print ("<html>")
+91-
9928016
print ("<head>")
d y
print ("<title>Hello - Second CGI Program</title>")
573
print ("</head>")
t u
print ("<body>")
S
print ("<h2>Hello %s %s</h2>" % (first_name,
last_name)) D
print ("</body>")
print ("</html>")
J M
This would generate the following result −
Hello ZARA ALI

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 22
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Simple FORM Example:GET Method
JMD Study Computer Classes
and
Sharm This example passes two values using HTML FORM
a and submit button. We use same CGI script
+91-
9928016
hello_get.py to handle this input.
d y
573

"get"> t u
<form action = "/cgi-bin/hello_get.py" method =

S
First Name: <input type = "text" name =
"first_name"> <br /> D
/> J M
Last Name: <input type = "text" name = "last_name"

<input type = "submit" value = "Submit" />


</form>

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 23
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan Simple FORM Example:GET Method
JMD Study Computer Classes
and
Sharm Here is the actual output of the above form, you
a enter First and Last Name and then click submit
+91-
9928016
button to see the result.
d y
573
t u
S
D
J M

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 24
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Passing Information Using POST Method
JMD Study Computer Classes
and
Sharm A generally more reliable method of passing
a
information to a CGI program is the POST method. This
+91-
9928016
d y
packages the information in exactly the same way as
GET methods, but instead of sending it as a text string
573
t u
after a ? in the URL it sends it as a separate message.
This message comes into the CGI script in the form of
the standard input.
S
Below is same hello_get.py script which handles GET as
well as POST method. D
import cgi, cgitb
J M
# Import modules for CGI handling
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 25
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan
Passing Information Using POST Method
JMD Study Computer Classes
and
Sharm first_name = form.getvalue('first_name')
a last_name = form.getvalue('last_name')
+91-
9928016
print "Content-type:text/html\r\n\r\n"
print "<html>" d y
573
print "<head>" t u
S
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>" D
J M
print "<h2>Hello %s %s</h2>" % (first_name, last_name)
print "</body>"
print "</html>"

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 26
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Passing Information Using POST Method
JMD Study Computer Classes
and
Sharm Let us take again same example as above which passes
a two values using HTML FORM and submit button. We
+91-
9928016
d y
use same CGI script hello_get.py to handle this input.
<form action = "/cgi-bin/hello_get.py" method = "post">
573
t u
First Name: <input type = "text" name = "first_name">
<br />
S
Last Name: <input type = "text" name = "last_name" />
D
<input type = "submit" value = "Submit" />
</form>
J M
Here is the actual output of the above form. You enter
First and Last Name and then click submit button to see
the result.

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 27
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan
Passing Information Using POST Method
JMD Study Computer Classes
and
Sharm
a
+91-
9928016
d y
573
t u
S
D
J M

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 28
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Passing Checkbox Data to CGI Program
JMD Study Computer Classes
and
Checkboxes are used when more than one option is
Sharm required to be selected.
a
+91-
9928016

d y
Here is example HTML code for a form with two checkboxes
<form action = "/cgi-bin/checkbox.cgi" method = "POST"
573
target = "_blank">
t u
S
<input type = "checkbox" name = "maths" value = "on" />
Maths

D
<input type = "checkbox" name = "physics" value = "on" />
Physics
</form>
J M
<input type = "submit" value = "Select Subject" />
The result of this code is the following form −
Maths Physics
Below is checkbox.cgi script to handle input given by web
browser for checkbox button.

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 29
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan
Passing Checkbox Data to CGI Program
JMD Study Computer Classes
and
Sharm #!/usr/bin/python
a # Import modules for CGI handling
+91-
9928016
import cgi, cgitb
d y
573 # Create instance of FieldStorage
form = cgi.FieldStorage() t u
# Get data from fields S
if form.getvalue('maths'): D
math_flag = "ON"
else: J M
math_flag = "OFF"

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 30
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Passing Checkbox Data to CGI Program
JMD Study Computer Classes
and
if form.getvalue('physics'):
Sharm
physics_flag = "ON"
a
+91-
9928016
else:
physics_flag = "OFF"
d y
573 print "Content-type:text/html\r\n\r\n"
print "<html>" t u
print "<head>"
S
print "<title>Checkbox - Third CGI Program</title>"
print "</head>" D
print "<body>"
J M
print "<h2> CheckBox Maths is : %s</h2>" % math_flag
print "<h2> CheckBox Physics is : %s</h2>" % physics_flag
print "</body>"
print "</html>"

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCABCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/MCA/
M.Tech/ B.Tech/
M.Tech/ BCA Intenship/
B.Tech/ Industrial/
BCA Internship/ Live Project
Industrial/ Live Training.
Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 31
Project Training
Designing, Digital
in Python, Android,
Marketing, SEO,
PHP,
SMO,
ASP.NET,
C, C++.
C++. Call:
Machine Learning, SQL, JAVA,
Web Designing,
Web Designing, Digital
Digital Marketing,
Marketing, SEO,
SEO, SMO,
SMO, C, Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan
Passing Text Area Data to CGI Program
JMD Study Computer Classes
and TEXTAREA element is used when multiline text has to be
Sharm passed to the CGI Program.
a
+91-
9928016 box −
d y
Here is example HTML code for a form with a TEXTAREA
573
target = "_blank"> t u
<form action = "/cgi-bin/textarea.py" method = "post"

S
<textarea name = "textcontent" cols = "40" rows = "4">
Type your text here...
</textarea> D
J M
<input type = "submit" value = "Submit" />
</form>
The result of this code is the following form −

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 32
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by
Yogan
Training > Project > Placement Passing Text Area Data to CGI Program
JMD Study Computer Classes
and
Sharm Type your text here...
a Below is textarea.cgi script to handle input given by
+91-
9928016
web browser −
d y
573 # Import modules for CGI handling
import cgi, cgitb t u
# Create instance of FieldStorage S
form = cgi.FieldStorage() D
# Get data from fields
J M

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 33
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan
Passing Text Area Data to CGI Program
JMD Study Computer Classes
and
Sharm if form.getvalue('textcontent'):
a
text_content = form.getvalue('textcontent')
+91-
9928016
else:
text_content = "Not entered"
d y
573 print "Content-type:text/html\r\n\r\n"
print "<html>" t u
print "<head>";
S
print "<title>Text Area - Fifth CGI Program</title>"
print "</head>" D
print "<body>"
J M
print "<h2> Entered Text Content is %s</h2>" %
text_content
print "</body>"

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training
MCA/ in Python,B.Tech/
M.Tech/ Android, BCA
PHP, Internship/
ASP.NET, Machine Learning,
Industrial/ Live SQL, JAVA,
Project Web
Training.
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 34
MCA Notes
Internship.
Project Training in Python, Android,
http://sunshinesoftwares.com, PHP, ASP.NET, Machine Learning, SQL, JAVA,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship
C++. Call: 9649141215, forwww.jmdstudy.com
BPL)
Training
by Passing Drop Down Box Data to CGI Program
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Drop Down Box is used when we have many options
Sharm available but only one or two will be selected.
a
+91-
9928016
box −
d y
Here is example HTML code for a form with one drop down
<form action = "/cgi-bin/dropdown.py" method = "post"
573
target = "_blank">
t u
<select name = "dropdown">
S
<option value = "Maths" selected>Maths</option>

D
<option value = "Physics">Physics</option>
</select>
</form>
J M
<input type = "submit" value = "Submit"/>
The result of this code is the following form −

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 35
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by Passing Drop Down Box Data to CGI Program
Yogan
JMD Study Computer Classes
and
Sharm Below is dropdown.py script to handle input given
a by web browser.
+91-
9928016
#!/usr/bin/python
# Import modules for CGI handling d y
573
import cgi, cgitb t u
# Create instance of FieldStorage
form = cgi.FieldStorage()
S
# Get data from fields D
J M
if form.getvalue('dropdown'):
subject = form.getvalue('dropdown')
else:
subject = "Not entered"

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 36
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training
by Passing Drop Down Box Data to CGI Program
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm print "Content-type:text/html\r\n\r\n"
a print "<html>"
+91-
9928016
print "<head>"
d y
573 print "<title>Dropdown Box - Sixth CGI
Program</title>" t u
print "</head>" S
print "<body>" D
print "</body>" J M
print "<h2> Selected Subject is %s</h2>" % subject

print "</html>"

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 37
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Assistance Using Cookies in CGI


by
Yogan > Placement
Classes
ComputerClasses
and
Sharm HTTP protocol is a stateless protocol. For a
a commercial website, it is required to maintain
+91-
session information among different pages. For
d y
& 100%Job
StudyComputer

9928016
573
t u
example, one user registration ends after
completing many pages. How to maintain user's
S
> Project

session information across all the web pages?


D
In many situations, using cookies is the most
M
efficient method of remembering and tracking
JMDStudy

J
Project

preferences, purchases, commissions, and other


Training

information required for better visitor experience


JMD

or site statistics.
Live

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 38
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

How It Works?
by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm Your server sends some data to the visitor's browser in
a the form of a cookie. The browser may accept the
+91-
9928016
d y
cookie. If it does, it is stored as a plain text record on the
visitor's hard drive. Now, when the visitor arrives at
573
t u
another page on your site, the cookie is available for
S
retrieval. Once retrieved, your server
knows/remembers what was stored.
D
Cookies are a plain text data record of 5 variable-length
fields −
J M
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.
MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 39
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Assistance How It Works?


by
Yogan > Placement
Classes
ComputerClasses
and
Sharm Secure − If this field contains the word "secure",
a then the cookie may only be retrieved with a secure
+91-

d y
server. If this field is blank, no such restriction exists.
& 100%Job
StudyComputer

9928016
573

form of key and value pairs. t u


Name = Value − Cookies are set and retrieved in the

S
> Project

D
M
JMDStudy

J
Project
Training
JMD
Live

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 40
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

Setting up Cookies
by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm It is very easy to send cookies to browser. These
a cookies are sent along with HTTP Header before to
+91-
9928016
Content-type field. Assuming you want to set
UserID and Password as cookies. Setting the d y
573
cookies is done as follows − t u
#!/usr/bin/python
print "Set-Cookie:UserID = XYZ;\r\n"
S
D
print "Set-Cookie:Password = XYZ123;\r\n"

23:12:40 GMT;\r\n" J M
print "Set-Cookie:Expires = Tuesday, 31-Dec-2007

print "Set-Cookie:Domain =
www.jmdstudy.com;\r\n"
print "Set-Cookie:Path = /perl;\n"
MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 41
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance Setting up Cookies


by
Yogan
JMD Study Computer Classes
and
Sharm print "Content-type:text/html\r\n\r\n"
a ...........Rest of the HTML Content....
+91-
9928016
From this example, you must have understood
d y
573

to set cookies. t u
how to set cookies. We use Set-Cookie HTTP header

S
It is optional to set cookies attributes like Expires,
D
Domain, and Path. It is notable that cookies are set

J M
before sending magic line "Content-
type:text/html\r\n\r\n.

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 42
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

Retrieving Cookies
by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm It is very easy to retrieve all the set cookies. Cookies
a are stored in CGI environment variable
+91-
9928016
HTTP_COOKIE and they will have following form −
d y
573
t u
key1 = value1;key2 = value2;key3 = value3....
Here is an example of how to retrieve cookies.
#!/usr/bin/python S
D
# Import modules for CGI handling
from os import environ
import cgi, cgitb J M

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 43
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance Retrieving Cookies


by
JMD Study Computer Classes
Yogan
and
Sharm if environ.has_key('HTTP_COOKIE'):
a for cookie in map(strip, split(environ['HTTP_COOKIE'],
+91-
9928016
';')):
(key, value ) = split(cookie, '='); d y
573
if key == "UserID":
t u
user_id = value
if key == "Password": S
password = value D
J M
print "User ID = %s" % user_id
print "Password = %s" % password
Output:
User ID = XYZ
Password = XYZ123

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 44
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)
Training

File Upload Example


by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm To upload a file, the HTML form must have the enctype
a attribute set to multipart/form-data. The input tag with
+91-
9928016
the file type creates a "Browse" button.
<html> d y
573
<body>
t u
S
<form enctype = "multipart/form-data" action =
"save_file.py" method = "post">
D
<p>File: <input type = "file" name = "filename" /></p>

</form>
J M
<p><input type = "submit" value = "Upload" /></p>

</body>
</html>
The result of this code is the following form −

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 45
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance File Upload Example


by
Yogan
JMD Study Computer Classes
and
Sharm Above example has been disabled intentionally to
a save people uploading file on our server, but you
+91-
9928016
can try above code with your server.
d y
573

#!/usr/bin/python t u
Here is the script save_file.py to handle file upload −

import cgi, os S
import cgitb; cgitb.enable()D
J
# Get filename here.
M
form = cgi.FieldStorage()

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project MCA/ M.Tech/
Training B.Tech/
in Python, BCA PHP,
Android, Internship/ Industrial/
ASP.NET, MachineLive ProjectSQL,
Learning, Training.
JAVA, Web
Project
Project Trainingin
Training
Designing, inPython,
Python,
Digital Android,
Android,
Marketing, PHP,
PHP,
SEO, ASP.NET,
ASP.NET,
SMO, C, Machine
Machine
C++, B.Tech /Python Learning,
Notes
Learning,
MCA SQL, SQL,
Internship. JAVA,JAVA, 46
Web http://sunshinesoftwares.com,
Web Designing,
Designing, DigitalMarketing,
Digital Marketing, Call:
SEO,
SEO, 9928016573,
SMO,
SMO, C, 9887116583,
C, C++. C++.
Call:Call: (Scholarship
9649141215,
9649141215, forwww.jmdstudy.com
BPL)
www.jmdstudy.com
Training

File Upload Example


by
Yogan
Training > Project > Placement
JMD Study Computer Classes
and
Sharm fileitem = form['filename']
a # Test if the file was uploaded
+91-
9928016
if fileitem.filename:
d
# strip leading path from file name to avoid
y
573
# directory traversal attacks t u
S
fn = os.path.basename(fileitem.filename)
open('/tmp/' + fn, 'wb').write(fileitem.file.read())
D
message = 'The file "' + fn + '" was uploaded
successfully'
else: J M
message = 'No file was uploaded'

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 47
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance File Upload Example


by
Yogan
JMD Study Computer Classes
and
Sharm print """\
a
Content-Type: text/html\n
+91-
9928016
<html>
<body>
d y
573 <p>%s</p>
</body> t u
</html>
""" % (message,) S
D
If you run the above script on Unix/Linux, then you

J M
need to take care of replacing file separator as follows,
otherwise on your windows machine above open()
statement should work fine.
fn = os.path.basename(fileitem.filename.replace("\\", "/"
))

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project MCA/ M.Tech/
Training B.Tech/
in Python, BCA PHP,
Android, Internship/ Industrial/
ASP.NET, MachineLive ProjectSQL,
Learning, Training.
JAVA, Web
Project
Project Trainingin
Training
Designing, inPython,
Python,
Digital Android,
Android,
Marketing, PHP,
PHP,
SEO, ASP.NET,
ASP.NET,
SMO, C, Machine
Machine
C++, B.Tech /Python Learning,
Notes
Learning,
MCA SQL, SQL,
Internship. JAVA,JAVA, 48
Web http://sunshinesoftwares.com,
Web Designing,
Designing, DigitalMarketing,
Digital Marketing, Call:
SEO,
SEO, 9928016573,
SMO,
SMO, C, 9887116583,
C, C++. C++.
Call:Call: (Scholarship
9649141215,
9649141215, forwww.jmdstudy.com
BPL)
www.jmdstudy.com
Training
by
Yogan
How To Raise a "File Download" Dialog Box?
Training > Project > Placement
JMD Study Computer Classes
and
Sharm Sometimes, it is desired that you want to give option
a
where a user can click a link and it will pop up a "File
+91-
9928016
Download" dialogue box to the user instead of
d y
displaying actual content. This is very easy and can be
573
t u
achieved through HTTP header. This HTTP header is be
different from the header mentioned in previous
section.
S
For example, if you want make a FileName file
D
downloadable from a given link, then its syntax is as
follows −
#!/usr/bin/python
# HTTP Header J M
print "Content-Type:application/octet-stream; name =
\"FileName\"\r\n";

MCA/M.Tech/
MCA/ M.Tech/ B.Tech/
B.Tech/ BCA
BCA Internship/
Internship/ Industrial/
Industrial/ Live Live Project
Project Training.
Training.
MCA/ M.Tech/ B.Tech/ BCA Intenship/ Industrial/ Live Project Training.
Project
Project
Project Training
Training
Training inininPython,
Python,
Python, Android,
Android,
Android, PHP,
PHP,
PHP, ASP.NET,
ASP.NET,
ASP.NET, Machine
Machine
Machine Python Learning,
Notes
Learning,
Learning, SQL, SQL,
SQL,Web
JAVA, JAVA,JAVA, 49
Web Designing,
Web Designing,
Designing, Digital
Digital
Digital Marketing,
Marketing,
Marketing, SEO,
SEO,
SEO, SMO,
SMO,
SMO, C, C++.
C, C++. Call:
Call:9928016573,
C, C++. Call: 9887116583
9649141215,
9649141215, www.jmdstudy.com
www.jmdstudy.com
Training

Live Project & 100%Job Assistance


by
Yogan
How To Raise a "File Download" Dialog Box?
JMD Study Computer Classes
and
Sharm print "Content-Disposition: attachment; filename =
a \"FileName\"\r\n\n";
+91-
9928016
# Actual File Content will go here.
d y
573 fo = open("foo.txt", "rb")
str = fo.read(); t u
print str S
# Close opend file D
fo.close()
J M

MCA/ M.Tech/ B.Tech/ BCA Internship/ Industrial/ Live Project Training.


Project Training in Python, Android, PHP, ASP.NET, Machine Learning, SQL, JAVA, Web
Project TrainingDigital
Designing, in Python, Android,
Marketing, SEO,PHP, ASP.NET,
SMO, C, Machine
C++, B.Tech /Python Learning, SQL, JAVA, 50
MCA Notes
Internship.
http://sunshinesoftwares.com,
Web Designing, Digital Marketing,Call:
SEO, 9928016573,
SMO, C, 9887116583, (Scholarship forwww.jmdstudy.com
C++. Call: 9649141215, BPL)

You might also like