Link to home
Start Free TrialLog in
Avatar of BabyFace
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.
Avatar of hansam
hansam

don't use cflocation there is a bug in it. There is a very simple very quick solution and that is:
-------------------------------
<cfcookie NAME="Basket" VALUE="" EXPIRES="NOW">

<script>
location.href='shoppingbasket.cfm';
</script>
-------------------------------
ASKER CERTIFIED SOLUTION
Avatar of tleish
tleish

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Hi,

Try using this,

<cfcookie NAME="Basket" VALUE="" EXPIRES="NOW">
<CFINCLUDE Template="shoppingbasket.cfm">
<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
Avatar of BabyFace

ASKER

Comment accepted as answer
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?