session和cookie的疑惑(解决者100分+追加分数)
发布网友
发布时间:2022-05-16 15:56
我来回答
共6个回答
热心网友
时间:2023-08-07 11:53
一楼二楼的明显有错误.
session:
文件1.asp和2.asp
HTML基本代码我不写了啊.
1.asp
<html>
<hitle>
这里不写了太多.
</hitle>
<body>
<%session("a")="123456"
session("b")="abcdef"%>
<a href="2.asp">下一页</a>
</body>
</html>
2.asp
<html>
<hitle>
这里也不写了.
</hitle>
<body>
<%aa=session("a")
bb=session("b")
response.write aa
response.write bb%>
</body>
</html>
注:上面的response.write aa直接用response.write session("a")也可以.
COOKIES
1.asp
<html>
<hitle>
同上,不写了太多.
</hitle>
<body>
<%
if request("x")="" then
Response.Cookies("aa") = "123456"
Response.Cookies("aa").Expires = #January 01, 2005#
Response.Cookies("bb") = "abcdef"
Response.Cookies("bb").Expires = #January 01, 2005#
response.write "aa的值是"&Request.Cookies("aa")
response.write "bb的值是"&Request.Cookies("bb")
else
Response.Cookies("aa") = ""
Response.Cookies("bb") = ""
end if
%>
<a href="2.asp">下一页</a>
</body>
</html>
2.asp
<html>
<hitle>
这里也不写了.
</hitle>
<body>
<%aa=Request.Cookies("aa")
bb=Request.Cookies("bb")
response.write aa
response.write bb%>
<a href="1.asp?x=1">返回</a>
</body>
</html>
注:我是在第一个页里面清楚的COOKIES值,建议使用他的属性日期来自动清除,比如一天或一个月,现在论坛一般都是这样的方法.如果用强制等于空的方法有点牵强.
如果值不是那么多的话用SESSION比较安全点,可能有写错字母的地方,你检查一下吧,我没有运行环境.
热心网友
时间:2023-08-07 11:54
Session 示例:
假设有 2 个 ASP 文件: session.asp & session2.asp。
session.asp:
<%
'leon2 编写于 2005/07/25,原创
'定义 Session 会话级变量
Session("myname") = "Billgates"
Session("company") = "Microsoft"
%>
<html>
<head>
<title>Session</title>
</head>
<body>
myname = <% =Session("myname")%>
company = <% =Session("company")%>
<a href="session2.asp">下一页</a>
</body>
</html>
session2.asp:
<html>
<head>
<title>Session</title>
</head>
<body>
myname = <% =Session("myname")%>
company = <% =Session("company")%>
<a href="session.asp">上一页</a>
</body>
</html>
Cookies 示例:
假设有 2 个 ASP 文件: cookie.asp & cookie2.asp。
cookie.asp:
<%
'设置 Cookie 值
Response.Cookies("myname") = "Billgates"
Response.Cookies("company") = "Microsoft"
%>
<html>
<head>
<title>Cookie</title>
</head>
<body>
myname = <% =Request.Cookies("myname")%>
company = <% =Request.Cookies("company")%>
<a href="cookie2.asp">下一页</a>
</body>
</html>
cookie2.asp:
<html>
<head>
<title>Cookie</title>
</head>
<body>
myname=<% =Request.Cookies("myname")%>
company<% =Request.Cookies("company")%>
<a href="cookie.asp">上一页</a>
</body>
</html>
热心网友
时间:2023-08-07 11:54
支持:
Session 示例:
假设有 2 个 ASP 文件: session.asp & session2.asp。
session.asp:
<%
'leon2 编写于 2005/07/25,原创
'定义 Session 会话级变量
Session("myname") = "Billgates"
Session("company") = "Microsoft"
%>
<html>
<head>
<title>Session</title>
</head>
<body>
Session("myname") = <% =Session("myname")%>
Session("company") = <% =Session("company")%>
<a href="session2.asp">下一页</a>
</body>
</html>
session2.asp:
<html>
<head>
<title>Session</title>
</head>
<body>
Session("myname") = <% =Session("myname")%>
Session("company") = <% =Session("company")%>
<a href="session.asp">上一页</a>
</body>
</html>
Cookies 示例:
假设有 2 个 ASP 文件: cookie.asp & cookie2.asp。
cookie.asp:
<%
'设置 Cookie 值
Response.Cookies("myname") = "Billgates"
Response.Cookies("company") = "Microsoft"
%>
<html>
<head>
<title>Cookie</title>
</head>
<body>
Request.Cookies("myname") =
<% =Request.Cookies("myname")%>
Request.Cookies("company") =
<% =Request.Cookies("company")%>
<a href="cookie2.asp">下一页</a>
</body>
</html>
cookie2.asp:
<html>
<head>
<title>Cookie</title>
</head>
<body>
Request.Cookies("myname") =
<% =Request.Cookies("myname")%>
Request.Cookies("company") =
<% =Request.Cookies("company")%>
<a href="cookie.asp">上一页</a>
</body>
</html>
热心网友
时间:2023-08-07 11:55
为安全起见还是用session好些,只是session战用资源较多,尽量放少些东西在SESSION里,COOKIE不提倡.
热心网友
时间:2023-08-07 11:55
http://www.66study.com/Article/web/ASP/jichu/200505/16392.html
http://www.cowcow.us/wanglo/P0HP/PHPYY/200504/3497.html
http://web.xiameng.net/n2402c120.aspx
http://www.yndxs.com/blog/more.asp?name=sydney&id=143
帮你找的这些网页,你自己看看吧!!!
希望对你有帮助!!
热心网友
时间:2023-08-07 11:56
支持使用response.write的朋友...