奇怪的cookies丢失问题

Equn 2007-06-28 05:05:43
网站:http://sh.ailv.cn
在向购物车增加第12个商品时,三个商品的cookies数据丢失,以后每向购物车增加一个商品,就丢失一个,一直保留8个商品cookies。太奇怪了。

代码如下:
<!--#include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>购物车</title>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-color: #F5E9ED;
}
-->
</style></head>

<body>
<table width="563" height="174" border="0" cellpadding="0" cellspacing="8" bgcolor="FFDEEA">
<tr>
<td valign="top" bgcolor="#FFFFFF">
<%
if request.QueryString("action")="reset" then
idlist=request.Cookies("idlist")
idlist1=request.Form("id")
id=split(idlist,",")
id1=split(idlist1,",")

'删除选购商品
for i=0 to ubound(id)
if len(id(i))>0 then
del=true
for j=0 to ubound(id1)
if clng(id1(j))=clng(id(i)) then
del=false
exit for
end if
next
if del then
response.Cookies("pro"&id(i)).expires="1/1/1998"
end if
end if
next

'修改选购商品定购件数
dim errmsg,cnum
for j=0 to ubound(id1)
keyname=clng(id1(j))
cnum=clng(request.Form("m_"&keyname))
if cnum=0 then
errmsg="修改数量失败,订单商品数量为0!"
else
response.Cookies("pro"&keyname)("num")=cnum
end if
next
response.Cookies("idlist")=idlist1&","
if len(errmsg)>0 then
response.Write("<script language=javascript>alert('"&errmsg&"');location.href='buy.asp';</script>")
response.End()
else
response.Redirect("buy.asp")
end if
elseif request.QueryString("action")="clear" then
idlist=request.Cookies("idlist")
id=split(idlist,",")
for i=0 to ubound(id)
if len(trim(id(i)))>0 then
keyname="pro"&clng(id(i))
response.Cookies(keyname).expires="1/1/1998"
end if
next
response.Cookies("idlist")=""
response.Redirect("buy.asp")
elseif request.QueryString("id")<>"" then
proid=clng(request.QueryString("id"))
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from v_uid_pro where uid="&request.Cookies("uid")&" and isview=1 and id=" & proid,conn,1,1

idlist=request.Cookies("idlist")
id=split(idlist,",")
have=false
for i=0 to ubound(id)
if len(id(i))>0 then
if proid=clng(id(i)) then
have=true
exit for
end if
end if
next

if not have then
response.Cookies("idlist")=idlist&proid&","
response.Cookies("idlist").expires="1/1/2038"
else
response.Redirect("buy.asp")
response.End()
end if

keyname="pro"&proid
response.Cookies(keyname).expires="1/1/2038"
response.Cookies(keyname)("id")=proid
response.Cookies(keyname)("number")=rs("number")
response.Cookies(keyname)("name")=rs("name")
if isnull(rs("brand")) then
response.Cookies(keyname)("brand")=""
else
response.Cookies(keyname)("brand")=rs("brand")
end if
response.Cookies(keyname)("price")=rs("price")
response.Cookies(keyname)("new_price")=rs("new_price")
response.Cookies(keyname)("unit")="元/"&rs("unit")
response.Cookies(keyname)("num")="1"
response.Redirect("buy.asp")
end if
all_price=0
all_num=0
if len(request.Cookies("idlist"))=0 then
call no_pro
else
%>
<form name="form1" method="post" action="?action=reset">
<table width="547" border="0" cellpadding="0" cellspacing="0" class="css_gray">
<tr>
<td width="11" height="36"> </td>
<td width="526" align="center"><font color="#333333" size="3"><strong>以下是您所选购的商品清单</strong></font></td>
<td width="10"> </td>
</tr>
<tr>
<td height="106"> </td>
<td valign="top">



<table width="520" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF" class="css_gray">
<tr>
<td width="40" height="24" align="center" bgcolor="FFDEEA">取消<br /></td>
<td width="179" bgcolor="FFDEEA"> 商品名称</td>
<td width="48" align="center" bgcolor="FFDEEA">市场价</td>
<td width="63" align="center" bgcolor="FFDEEA">爱侣价</td>
<td width="57" align="center" bgcolor="FFDEEA">计量单位</td>
<td width="51" align="center" bgcolor="FFDEEA">数量</td>
<td width="74" align="center" bgcolor="FFDEEA">总价</td>
</tr>
<%
idlist=request.Cookies("idlist")
id=split(idlist,",")
for i=0 to ubound(id)
if len(id(i))>0 then
lng_id=clng(id(i))
keyname="pro"&lng_id
if trim(request.Cookies(keyname)("num"))<>"" and trim(request.Cookies(keyname)("new_price"))<>"" then
price=clng(request.Cookies(keyname)("num"))*ccur(request.Cookies(keyname)("new_price"))
else
price=0
end if
all_num=all_num+clng(request.Cookies(keyname)("num"))
all_price=all_price+price

%>
<tr>
<td bgcolor="FFDEEA" align="center">
<input name="id" type="checkbox" id="id" value="<%=lng_id%>" checked>
</td>
<td bgcolor="FFDEEA"><%=request.Cookies(keyname)("name")%></td>
<td bgcolor="FFDEEA" align="center"><%=request.Cookies(keyname)("price")%></td>
<td bgcolor="FFDEEA" align="center"><%=request.Cookies(keyname)("new_price")%></td>
<td bgcolor="FFDEEA" align="center"><%=request.Cookies(keyname)("unit")%></td>
<td bgcolor="FFDEEA" align="center">
<input name="m_<%=lng_id%>" type="text" class="button-css" id="m_<%=lng_id%>" value="<%=request.Cookies(keyname)("num")%>" size="3">
</td>
<td bgcolor="FFDEEA" align="center"><%=price%></td>
</tr>
<%
end if
next
%>
<tr bgcolor="FFDEEA">
<td height="24" colspan="7" align="center">总价格:<font color="#CC0000"><%=all_price%>元</font></td>
</tr>
</table>


</td>
<td> </td>
</tr>

<tr>
<td> </td>
<td>

<table width="525" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="137"> </td>
<td width="78"><input type="submit" name="Submit" value="确认更改" style="background-color:FFC2D8;border-width:1px;border-color:#DD196D;border-style:solid;width:70px;height:18px;font-size:12px;color:404040;font-family:'宋体'"/>
</td>
<td width="77"><input type="Button" name="Button" value="继续购物" onClick="window.close();return true;" style="background-color:FFC2D8;border-width:1px;border-color:#DD196D;border-style:solid;width:70px;height:18px;font-size:12px;color:404040;font-family:'宋体'"/></td>
<td width="79"><input type="Button" name="Button" onClick="javascript:window.open('payment.asp');window.close();return true;" value="去收银台" style="background-color:FFC2D8;border-width:1px;border-color:#DD196D;border-style:solid;width:70px;height:18px;font-size:12px;color:404040;font-family:'宋体'"/></td>
<td width="154"><input type="Button" name="Button" value="清空购物车" onClick="javascript:location='buy.asp?action=clear'" style="background-color:FFC2D8;border-width:1px;border-color:#DD196D;border-style:solid;width:75px;height:18px;font-size:12px;color:404040;font-family:'宋体'"/></td>
</tr>
</table>

</td>
<td> </td>
</tr>
</table>
</form>
<%
end if
response.Cookies("all_price")=all_price '总价格
response.Cookies("all_num")=all_num '总数量
%>
</td>
</tr>
</table>
<%
sub no_pro
%>
<table width="553" height="181" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="1" bgcolor="#FF91BE"></td>
</tr>
<tr>
<td height="70" align="center" bgcolor="#F5E9ED"><span class="css">您目前还没有选购商品!</span></td>
</tr>
<tr>
<td height="1"></td>
</tr>
</table>
<%
end sub
%>
</body>
</html>
...全文
378 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
李睿_Lee 2007-06-28
  • 打赏
  • 举报
回复
没细看你的程序,但有一点我提一下,有没有数据太多,导致cookie没有保存下来的可能?因为cookie的大小是有限制的。
popsn 2007-06-28
  • 打赏
  • 举报
回复
还是把删除,添加,修改,刷新 这些操作变成一个Sub块来处理好,要不造成程序逻辑成运算乱了,所以很难跟踪那步造成丢失。
改成函数(过程)后执行提交操作,只需检查 action的条件来决定执行添加,修改,刷新,删除。等。
Equn 2007-06-28
  • 打赏
  • 举报
回复
up

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧