posts - 110, comments - 101, trackbacks - 0, articles - 7
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

摘抄: 判断cookie是否开启

Posted on 2011-04-07 11:52 云云 阅读(2108) 评论(2)  编辑  收藏
方法一:

  无论何时你在两页之间,有一个非常简单可靠的方法:请求一个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
%>

评论

# re: 摘抄: 判断cookie是否开启  回复  更多评论   

2011-04-07 11:59 by 兵丸网络
正要用到这方面的知识。谢谢分享。

# re: 摘抄: 判断cookie是否开启  回复  更多评论   

2011-05-26 20:05 by

只有注册用户登录后才能发表评论。


网站导航: