BabyFace
asked on
Set cookie then redirect...
Hi,
I want to set a cookie then redirect my user to another page.
the code looks something like this...
<cfcookie NAME="Basket" VALUE="" EXPIRES="NOW">
<CFLOCATION URL="shoppingbasket.cfm">
The redirect works, but my cookie never gets set...
I think the cflocation blocks out my cfcookie statement...
How do I get around this?
Thanks.
I want to set a cookie then redirect my user to another page.
the code looks something like this...
<cfcookie NAME="Basket" VALUE="" EXPIRES="NOW">
<CFLOCATION URL="shoppingbasket.cfm">
The redirect works, but my cookie never gets set...
I think the cflocation blocks out my cfcookie statement...
How do I get around this?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You might want to look into using session or client variables to accomplish the same task. I was running into similar problems as yours and found that a simple session variable solved all my problems. Plenty of documentation around on their usage, so I won't bore you with details.
Good luck.
Good luck.
Hi,
Try using this,
<cfcookie NAME="Basket" VALUE="" EXPIRES="NOW">
<CFINCLUDE Template="shoppingbasket.c fm">
<CFABORT>
Try using this,
<cfcookie NAME="Basket" VALUE="" EXPIRES="NOW">
<CFINCLUDE Template="shoppingbasket.c
<CFABORT>
Here is an extract from CFDJ:
You KNOW you set the cookie, but it's vanished. The culprit here is the use of CFLOCATION on your page after the CFCOOKIE. Relocating the user to a different page effectively blows away the headers on your current page. Thus the browser never sees them - and never sets the cookie. This is not a CF problem but a Web problem. This can be avoided by using a JavaScript Location, but I haven't tried it.
So you can't use CFLOCATION whatsoever.
JS location.href="..." is the way to go.
CJ
You KNOW you set the cookie, but it's vanished. The culprit here is the use of CFLOCATION on your page after the CFCOOKIE. Relocating the user to a different page effectively blows away the headers on your current page. Thus the browser never sees them - and never sets the cookie. This is not a CF problem but a Web problem. This can be avoided by using a JavaScript Location, but I haven't tried it.
So you can't use CFLOCATION whatsoever.
JS location.href="..." is the way to go.
CJ
ASKER
Comment accepted as answer
ASKER
Thanks alot.
What part of the answer did you use?
You can't do it in the application.cfm, so where is the most suitable place for it to be place?
--------------------------
<cfcookie NAME="Basket" VALUE="" EXPIRES="NOW">
<script>
location.href='shoppingbas
</script>
--------------------------