Python Chapter16 CGI.pptx
Python Chapter16 CGI.pptx
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
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.
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
J M
running successfully and you are able to run any
other CGI program 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, 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
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
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
6 S
Set-Cookie: String D
M
Set the cookie passed through the string
J
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
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/
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
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/
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
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
Location:box.
J M
produces a long string that appears in your browser's
"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"
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
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
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
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
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
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/
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
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
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
9928016
573
t u
example, one user registration ends after
completing many pages. How to maintain user's
S
> Project
J
Project
or site statistics.
Live
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
d y
server. If this field is blank, no such restriction exists.
& 100%Job
StudyComputer
9928016
573
S
> Project
D
M
JMDStudy
J
Project
Training
JMD
Live
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
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.
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
</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
#!/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/
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
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/
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