摘抄: 判断cookie是否开启

方法一:

  无论何时你在两页之间,有一个非常简单可靠的方法:请求一个SessionID在第一页,传递它到下一页。与这一页请求到的SessionID比较。相同说明客户端浏览器接受Cookies;不同则不接受。很简单吧。

  比如你可以在第一页中放一个(hidden field),并把SessionID写入它。提交后,从页面数据中取出SessionID.像这样:

< form name = " Form1 "  method = " post "  action = " sessions2.asp " >
UserName:
< input name = " username " >< br >
Password:
< input name = " userpassword " >
< input type = " hidden "  name = " theSessionID "  value = " <%=Session.SessionID%> " >< br >
< input type = " submit "  value = " Submit " >
</ form >

  在第二页中我们来判断SessionID是否相同。

<%
dim theSessionID
theSessionID 
=  Request.Form( " theSessionID " )
If theSessionID 
=  Session.SessionID Then
" 当二者相等时,则cookie功能开启
Response.Write  " Cookie已开启 "
Else
" 若二者相等时,则cookie功能关闭
Response.Write  " Cookie没有开启! "
End If
%>

方法二:

  也可用这种方法,首先在一个页面里写入一个cookie,如:

<%
Response.Cookies(
" status " ) = " onoroff "
%>
  在第二页里读出此cookie:
<%
if  Request.Cookies( " status " ) = ""  then
" 当cookies( " status " )里没有值时,则cookie功能没有开启
Response.Write  " Cookie没有开启! "
else
" 当cookies( " status " )里有值时,则cookie功能开启
Response.Write  " Cookie已开启 "
end 
if
%>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值