如何在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 红包祝福语简短10字
18 周六早晨祝福语简短