

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- 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 download image using Python CGI Programming?
- How to write first Hello World program using CGI programming in Python?
- 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 good modules to be used for Python CGI Programming?
- How to raise a "File Download" Dialog Box in Python CGI Programming?
- How to pass variable in one Python CGI script to other Python CGI script?
- What folder permission I should use to work with Python CGI Programming?
Advertisements