-
Notifications
You must be signed in to change notification settings - Fork 0
/
p.py
94 lines (68 loc) · 2.48 KB
/
p.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python
import http
import datetime
import random
import os ,http.cookiejar
"""
print("Set-Cookie:UserID=XYZ;\r\n")
print("Set-Cookie:Password=XYZ123;\r\n")
print("Set-Cookie:Expires=Tuesday, 31-Dec-2027 23:12:40 GMT\r\n")
print("Set-Cookie:Domain=www.tutorialspoint.com;\r\n")
print("Set-Cookie:Path=/perl;\n")
print("Content-type:text/html\r\n\r\n")
"""
print("")
print("<html>")
print("<head>")
print("</head>")
print("<body>")
print("<h1>Mark Loves Python</h1>")
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
fish = form.getvalue('fish')
beer = form.getvalue('beer')
print("<h2>Hello: %s %s</h2>" % (first_name, last_name))
print("Fish:",fish==form.getvalue('fish'),"<br>")
print("Beer:",fish==form.getvalue('beer'),"<br>")
print("Gender:",form.getvalue('Gender'),"<br>")
print("About yourself:",form.getvalue('textcontent'),"<br>")
print("Country:",form.getvalue('Country'),"<br>")
print("<br>==================START==================<br>")
#for param in list(os.environ.keys()):
#print(param,os.environ[param],"<br>")
cookie_string = os.environ.get('HTTP_COOKIE')
#print("HTTP_COOKIE=",cookie_string)
if 'HTTP_COOKIE' in list(os.environ.keys()):
#print("<br>yes<br>")
cookies = os.environ['HTTP_COOKIE']
cookies = cookies.split(';')
#print(("cookies=",cookies))
handler = {}
for cookie in cookies:
cookie = cookie.split('=')
handler[cookie[0]] = cookie[1]
print(handler)
print("<br>==================FINISH==================<br>")
#print((list(os.environ.keys()),"<br>------------<br>")) # holds all the environment variables
for param in list(os.environ.keys()):
#print(list(param,os.environ[param]),"<br>")
if (param=="HTTP_COOKIE"):
print("<br><br><hr><font color=blue size=+3>Here are your cookies driven from<b>",param,"</b>:</font><br>")
print("complete string:<font color=green>",os.environ[param],"</font><br>")
newss=os.environ[param].split(";")
print (newss)
#print("newss=",newss[1],"<br>")
for n in newss:
(key, value ) = n.split('=')
first=key
second=value
print( "<font color=blue>",first, "</font>;",second,"<br>" )
if (param=="SERVER_SOFTWARE"):
print("SERVER_SOFTWARE=",os.environ[param],"<br>")
print("</body>")
print("</html>")