- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 setup cookies in Python CGI Programming?
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. Setting the cookies is done as follows −
#!/usr/bin/python print "Set-Cookie:UserID = XYZ;\r\n" print "Set-Cookie:Password = XYZ123;\r\n" print "Set-Cookie:Expires = Tuesday, 31-Dec-2007 23:12:40 GMT;\r\n" print "Set-Cookie:Domain = www.tutorialspoint.com;\r\n" print "Set-Cookie:Path = /perl;\n" print "Content-type:text/html\r\n\r\n" ...........Rest of the HTML Content....
From this example, you must have understood how to set cookies. We use Set-Cookie HTTP header to set cookies.
It is optional to set cookies attributes like Expires, Domain, and Path. It is notable that cookies are set before sending magic line "Content-type:text/html\r\n\r\n.
- How to retrieve 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 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?