如何在Python CGI编程中检索cookie?
检索Cookie
检索所有设置的cookie非常容易。Cookies存储在CGI环境变量HTTP_COOKIE中,它们具有以下形式-
key1 = value1;key2 = value2;key3 = value3....
这是有关如何获取Cookie的示例。
#!/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这将为上述脚本设置的cookie产生以下结果-
User ID = XYZ Password = XYZ123
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短