文章摘要
这篇文章主要介绍了如何使用 cookies 和数据库来管理用户的踩踏记录。代码中定义了变量 `mycookies` 用于记录用户是否已有踩踏记录,`id` 用于唯一识别每个踩踏操作。文章描述了前端如何从 `request` 对象中获取 `id` 和 `dingcai`(踩踏类型),并通过 cookies 判断用户是否已有记录。当用户提交有效的 `id` 和 `dingcai` 时,前端会更新数据库中的记录,并根据记录是否存在将结果写入 cookie 中。此外,文章提到 `mycookies` 的默认值为 0,表示用户首次操作时将被视为未有记录。代码还设置了 cookie 的有效性时间为24小时,确保记录在有效期内。
mycookies=0
id=clng(request.form(“id”))
dingcai=request.form(“dingcai”)
if id<>”” then
if request.cookies(“mycookies”&id)<>id then
‘写入cookies,有效期24小时
Response.cookies(“mycookies”&id)=id
Response.Cookies(“mycookies”&id).expires=dateadd(“H”,24,now())
else
mycookies=1
end if
else
mycookies=1
end if
mycookies=0
id=clng(request.form(“id”))
dingcai=request.form(“dingcai”)
if id<>”” then
if request.cookies(“mycookies”&id)<>id then
‘写入cookies,有效期24小时
Response.cookies(“mycookies”&id)=id
Response.Cookies(“mycookies”&id).expires=dateadd(“H”,24,now())
else
mycookies=1
end if
else
mycookies=1
end if
‘接受对应的id
‘如果顶踩过来的id不为空,并且获取是顶的操作或踩的操作
if request.form(“id”)<>”” and request.form(“dingcai”)<>”” then
‘如果是顶的操作
if dingcai=1 then
sql=”update dingcai set ding=ding+1 where id=”&id
else
sql=”update dingcai set cai=cai+1 where id=”&id
end if
if mycookies=0 then
conn.execute(sql)
response.write “yang_yes”
else
response.write “yang_no”
end if
end if
© 版权声明
文章版权归作者所有,未经允许请勿转载。



