Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The program of how to retrieve cookie information by CGI

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 231

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report