- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to retrieve cookies in Python CGI Programming?
Retrieving Cookies
It is very easy to retrieve all the set cookies. Cookies are stored in CGI environment variable HTTP_COOKIE and they will have following form −
key1 = value1;key2 = value2;key3 = value3....
Here is an example of how to retrieve cookies.
#!/usr/bin/python # Import modules for CGI handling from os import environ import cgi, cgitb if environ.has_key('HTTP_COOKIE'): for cookie in map(strip, split(environ['HTTP_COOKIE'], ';')): (key, value ) = split(cookie, '='); if key == "UserID": user_id = value if key == "Password": password = value print "User ID = %s" % user_id print "Password = %s" % password
This produces the following result for the cookies set by above script −
User ID = XYZ Password = XYZ123
- Related Articles
- How to setup cookies in Python CGI Programming?
- How do cookies work in Python CGI Programming?
- Using Cookies in CGI in Python
- How to do CGI programming in Python?
- How to use Cookies in CGI in Perl?
- How to configure Apache for Python CGI Programming?
- How to write first Hello World program using CGI programming in Python?
- How to raise a "File Download" Dialog Box in Python CGI Programming?
- What are environment variables available in Python CGI Programming?
- How do we do a file upload using Python CGI Programming?
- What are the modules required for CGI programming in Python?
- What are important HTTP headers to be frequently used in Python CGI Programming?
- What is the difference between GET and POST in Python CGI Programming?
- How to pass Checkbox Data to Python CGI script?
- How to read all HTTP headers in Python CGI script?

Advertisements