- 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
" print "Set-Cookie:Password = XYZ123;\r
" print "Set-Cookie:Expires = Tuesday, 31-Dec-2007 23:12:40 GMT;\r
" print "Set-Cookie:Domain = www.tutorialspoint.com;\r
" print "Set-Cookie:Path = /perl;
" print "Content-type:text/html\r
" ...........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
- 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 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?
- How to raise a "File Download" Dialog Box in Python CGI Programming?
- 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?
- What is CGI in Python?
- First CGI Program in Python