您现在的位置: 无忧电子商务网 >> 信息学院 >> 程序开发 >> asp >> 正文

通过ASP在Flash中妙用Cookie

作者:作者:未…    信息学院来源:网络收集    点击数:    更新时间:2006-8-27 我要参与讨论

  ' Check whether the session variable contains the value
If Session("__FlashCookieTest") = True Then
' Session variable contains value
' Thus browser accepts cookies
strOut = "Cookies=true"
Else
' Session variable is empty
' Thus browser does not accept cookies
strOut = "Cookies=false"
End If
End If
' Output to Flash:
Response.Write(strOut)
%>


Simply put, the script sets a session variable, performs a redirect onto itself and then checks whether
the value still is set in the session variable. For this value to stay saved, the browser must have
accepted the session cookie of the Internet Information Server (IIS) which is automatically sent to the
browser by ASP. This means that the browser accepts cookies when the value in the session variable is
still present after a redirect.

The file returns the text 'Cookies=true' if the browser accepts cookies or 'Cookies=false' if the browser
does not accept cookies.

When Flash calls the file testcookies.asp via the Flash command Load Variables, the ASP file returns
either the string "Cookies=true" or "Cookies=false" to the Flash file which automatically sets the
variable Cookies to "true" or "false" in Flash.

Setting Cookies
In ASP, cookies can be set easily using the Response.Cookies collection. In our example, the Flash file
calls the file setcookies.asp and passes the variables for the cookies (names and values) in the
Querystring to the ASP Script.

The ASP Script reads all values out of the Querystring collection sends the corresponding cookies via
Response.Cookies to the browser. The complete ASP script consists of only three lines:


<%
For each item in Request.QueryString
Response.Cookies(item) = Request.Querystring(item)
Next
%>


Reading Cookies
Reading the cookies and writing them to the Flash File is about as easy as setting the cookies. When the
Flash file calls the file getcookies.asp, it returns all the names and values of the cookies as URL-
encoded text. This way, the values of the cookes are written to variables of the same names in Flash when
Flash calls the filegetcookies.asp.

The ASP file getcookies.asp is as follows:


<%
For each cookie in Request.Cookies
strOut = strOut & Server.URLEncode(cookie) & "="
strOut = strOut & Server.URLEncode(Request.Cookies(cookie))
strOut = strOut & "&"
Next
Response.Write strOut
%>


Conclusion
The Flash based part of this article was created using Flash 4. The systematics are the same for the newly
published Version 5 of the Macromedia software.

The ASP part runs on IIS 4.0 as well as on IIS 5.0 and with slight modifications also under ASP+.

After having described setting and reading of coo

上一页  [1] [2] [3] [4] 下一页

在google里搜索更多通过ASP在Flash中妙用Cookie

Google
Web www.51ec.org
【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
我来说两句 对此文章发表了评论
  昵 称: *必填    ·注册用户·
  评 分: 1分 2分 3分 4分 5分     严禁发表危害国家安全、政治、黄色淫秽等内容的评论,用户需对自己在使用本网站服务过程中的行为承担法律责任。本站管理员有权保留或删除评论内容,评论内容只代表机友个人观点,与本网站立场无关。  
评 论
内 容

 
评论列表 (最新 评论仅限网友观点!)

供求信息




| 设为首页 | 加入收藏 | 关于我们 | 广告服务 | 联系方式 | 友情链接 | 版权申明