The program of how to retrieve cookie information by CGI
This article mainly introduces CGI how to retrieve cookie information related knowledge of the program, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this CGI how to retrieve cookie information of the program article will have a harvest, let's take a look.
Retrieve Cookie information
The Cookie information retrieval page is very simple. The Cookie information is stored in the environment variable HTTP_COOKIE of CGI in the following format:
Key1=value1;key2=value2;key3=value3....
The following is a simple program for CGI to retrieve cookie information:
#! / usr/bin/python3
# Import module
Import os
Import http.cookies
Print ("Content-type: text/html")
Print ()
Print ("
Rookie course (runoob.com)
Read cookie information
"")
If 'HTTP_COOKIE' in os.environ:
Cookie_string=os.environ.get ('HTTP_COOKIE')
C = http.cookies.SimpleCookie ()
# c=Cookie.SimpleCookie ()
C.load (cookie_string)
Try:
Data=c ['name']. Value
Print ("cookie data:" + data+ "
")
Except KeyError:
Print ("cookie is not set or has passed
")
Print ("
"")
Save the above code to cookie_get.py and modify the cookie_get.py permissions:
Chmod 755 cookie_get.py on "CGI how to retrieve cookie information program" this article is introduced here, thank you for reading! I believe that everyone has a certain understanding of the "CGI how to retrieve cookie information procedures" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.