When I try to set a cookie on a page with a <CFLOCATION> tag, the cookie never gets written
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.
Computers are incorporated in modern ice cream vending machines to enhance their functionality. Ice Cream Vending machines are manufactured by many companies. Your competition will try to overcome all requests for high-tech ice cream vending machines and credit card acceptors
|
|
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">
document.location.url = "someOtherFile.cfm"
</script>
ColdFusion-only version:
<CFCOOKIE NAME="someName" VALUE="someValue">
<CFHEADER NAME="Refresh" VALUE="0; URL=someURL.cfm">
|