I have the code below on a Linux web server. When a user clicked on a web page, the code below got executed. The first time it runs, it gives a time value in second such as 1093274703.0. 10 seconds later, the user clicked the same web page the second time,
and the message "time has exceed 10 seconds" suppose to appear on the web page, but it is not. This happens because the key COOKIE_TIME_STAMP which was created the first time the user click on a web page does not existed when he clicked on the web page a second time.
==========================
=======
def get_cookie():
found_key = "false"
cookie = Cookie.SmartCookie()
cookie.load(os.environ["HT
TP_COOKIE"
])
#The second time, the program is run the code below is suppose to be executed, and
# the key COOKIE_TIME_STAMP suppose to exist and therefore it is executed, but
# instead the key COOKIE_TIME_STAMP does not exist.
for key, item in cookie.items():
if key == "COOKIE_TIME_STAMP":
found_key = "true"
shell('echo "ok2" >> /usr/apache/html/abc')
cookie_time_stamp_2 = item.value
time_difference = time.mktime(time.localtime
(time.time
())) - float
(cookie_time_stamp_2);
if (time_difference > 10):
return "time has exceed 10 seconds"
break;
# the first time the program run, the code below is executed.
# the code below is not suppose to run the second time because
# on the second time the key COOKIE_TIME_STAMP suppose to exist
# and therefore found_key is equal to true.
if found_key == "false":
cookie = Cookie.SimpleCookie()
cookie["COOKIE_TIME_STAMP"
] = time.mktime(time.localtime
(time.time
()))
os.environ["HTTP_COOKIE"] = str(cookie)
cookie = Cookie.SmartCookie()
cookie.load(os.environ["HT
TP_COOKIE"
])
for key, item in cookie.items():
if key == "COOKIE_TIME_STAMP":
latest_cookie_time_stamp = item.value
shell('echo "in else" >> /usr/apache/html/abc')
break;
else:
latest_cookie_time_stamp = 0
return latest_cookie_time_stamp
##########################
##########
##########
########
var_cookie_time_stamp = get_cookie();
Start Free Trial