文章作者 : Linkfoxo [ fengjf@novasprint.com ] Web URL : http://
上载日期 : 2000-11-21
原因很简单:
就是还没有来得急在用户端设置cookie时已经被跳转到其他页面了.请看下面的文章:
The Situation:
You have written some code that validates a user, then writes a cookie with the userID.
Once this is done, you use <cflocation> to take the user to a main menu...but when
you do so, you find the cookie was never set.
The Solution:
When is a bug not a bug? Well, in this case, the behavior is unwanted, but not
unexpected. But instead of dealving into the inner workings of the HTTP specification,
here are two easy ways to get the desired behavior. One uses just a bit of JavaScript and
the other is a pure CF solution. (Thanks to Jim Smith who provided me with the CF-only
solution.)
Javascript version:
<cfcookie name="userID" value="#validateUser.userID#">
<script language="javascript">
location.url = "someOtherFile.cfm"
</script>
[Note: the location property, "mainMenu.cfm" is a relative pathname. You can
also use absolute pathnames.]
ColdFusion-only version:
<CFCOOKIE NAME="someName" VALUE="someValue">
<CFHEADER NAME="Refresh" VALUE="0; URL=someURL.cfm">
|