Forum Moderators: coopster

Message Too Old, No Replies

setcookie issue resetting

cannot get to reset from page to page

         

weddingm

8:53 pm on Jul 14, 2008 (gmt 0)

10+ Year Member



I have on the top of many pages:

setcookie( "example" , $returntopage);
setcookie( "auth" , "ok" );

However, when going to multiple pages like web page a, b and c with the setcookie, the cookie is not overridden with the new value on each page.

For example, I have web page a, b and c. After completing forms, you can always return to the page (a, b, c) that started in all. I tried using javascript history but it doesn't account for people who don't complete the form w/o errors.

janharders

8:57 pm on Jul 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



do these sites all sit in the same directory?

setcookie sets the path to the current directory per default so you could have different cookies in different directories.

check out [php.net...] and pass all the parameters with the right values. If that's not helping, check the headers (Live HTTP Headers-Addon in Firefox) to see if the server actually sends the set-cookie-header every time it should.

weddingm

10:18 pm on Jul 14, 2008 (gmt 0)

10+ Year Member



It is in the same directory....but thaks for the heads up.

I now use below but it still won't override the old cookie to the new one:

$value='test';
setcookie( "cookie" , "", time()-60*60*24*30, '/');
setcookie( "cookie" , $value, time()+3600, '/');
setcookie( "auth" , "ok" );

janharders

3:12 pm on Jul 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



wait, you set the "cookie"-cookie twice in one script?
I'm not sure if that's the right thing to do (and what result it will produce).
did you check if the Set-Cookie-Header actually is sent?

weddingm

10:36 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



I will try removing line 2 above..... how do I check Set-Cookie-Header actually is sent?

janharders

11:33 pm on Jul 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you're using firefox (which you should, of course ;), give [addons.mozilla.org...] a try. it's an addon that will allow you to see the http-headers firefox sends and receives from the server.

[edited by: eelixduppy at 11:38 pm (utc) on July 15, 2008]

omoutop

6:58 am on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



try to print_r($_COOKIE) in each page to see what you get.
If you get nothing, then your cookie is empty
If you get some values, then your existing code to read the cookie data has problems.

weddingm

2:24 pm on Jul 16, 2008 (gmt 0)

10+ Year Member



Thanks all for the help. I changed all pages to

setcookie( "cookie" , $value, time()+3600, '/');
setcookie( "auth" , "ok" );

and all works great. I forgot to change ALL the pages before.

omoutop

5:31 am on Jul 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



why do you create the cookie in multiple pages?
you set the cookie in one page and you verify its existance/content in all the other pages

you dont have to create teh cookie in each page