rs.update jibie=rs("szd_jibie") call SaveCookie_shop() sub SaveCookie_shop() Response.Cookies("shop")("User")=user Response.Cookies("shop")("Password") = PassWord Response.Cookies("shop")("CookieDate") = CookieDate select case CookieDate case 0 ''not save case 1 Response.Cookies("shop").Expires=Date+1 case 2 Response.Cookies("shop").Expires=Date+31 case 3 Response.Cookies("shop").Expires=Date+365 end select end sub
检验是否登陆 以及用户级别
''************************************************** ''函数名:CheckUserLogined ''作 用:检查用户是否登录 ''参 数:无 ''返回值:True ----已经登录 '' False ---没有登录 ''************************************************** function CheckUserLogined() dim Logined,Password,rsLogin,sqlLogin Logined=True User=Request.Cookies("shop")("User") Password=Request.Cookies("shop")("Password") ''上面是获取cookie if User="" then Logined=False end if if Password="" then Logined=False end if if User="" then Logined=False jibie=9999 end if if Logined=True then user=replace(trim(user),"''","") password=replace(trim(password),"''","")
set rsLogin=server.createobject("adodb.recordset")
sqlLogin="select * from admin where szd_user =''" & user & "'' and szd_password =''" & password &"''" rsLogin.open sqlLogin,Conn,1,1 if rsLogin.bof and rsLogin.eof then Logined=False else if password<>rsLogin("szd_password") then Logined=False end if User=rsLogin("szd_user")
if rsLogin("szd_cookie")=1 then ValidDays=rsLogin("szd_session") elseif rsLogin("szd_cookie")=2 then ValidDays=rsLogin("szd_session")*30 elseif rsLogin("szd_cookie")=3 then ValidDays=rsLogin("szd_session")*365 end if ValidDays=ValidDays-DateDiff("D", rsLogin("szd_last_time"),now()) end if rsLogin.close set rsLogin=nothing end if CheckUserLogined=Logined end function
''************************************************** ''函数名:jibie ''作 用:检查用户级别 ''参 数:LevelNum-----要检查的级别值 ''返回值:级别名称 ''************************************************** function jibieok(jibie) select case jibie case 9999 jibie="游客" case 1 jibie="普通村名" case 2 jibie="勤劳村民" case 3 jibie="高级村民" case 4 jibie="老农" end select end function
Else response.write " < font color=''#666666''>欢迎</font><font color=#000080>" & Request.Cookies("shop")("User")& "</b></font><font color =''#666666''>,</font>"
end if if ValidDays>0 then response.write " < b><font color=blue>" & ValidDays & "<a href=''logout.asp''> 退出</a></font>" if ValidDays<=10 then end if else response.write " < b><font color=red>" & ValidDays & "<a href=''logout.asp''> 退出</a></font>"
dim ComeUrl ComeUrl=trim(request("ComeUrl")) if ComeUrl="" then ComeUrl=Request.ServerVariables("HTTP_REFERER") if ComeUrl="" then ComeUrl="index.asp" end if end if Response.Redirect ComeUrl %>
以下是原文作者的评论~ 老农修正:保存cookie的时候,原先是session的值,放在数据库里面,取出,写入默认值,这样一般用不到,通用的为: sub SaveCookie_tvillage() Response.Cookies("tvillage")("User")=user Response.Cookies("tvillage")("Password") = PassWord Response.Cookies("tvillage")("jibie") = jibie Response.Cookies("tvillage")("CookieDate") = CookieDate select case CookieDate case 0 ''not save case 1 Response.Cookies("tvillage").Expires=Date+1 case 2 Response.Cookies("tvillage").Expires=Date+31 case 3 Response.Cookies("tvillage").Expires=Date+365 end select end sub