Forum Moderators: coopster

Message Too Old, No Replies

The cookie will not be set if header() follows...

         

marbi

10:08 pm on Jan 28, 2003 (gmt 0)

10+ Year Member



PHP V4.2.3-NT
setcookie("PHPSESSID", session_id(), 0, "/beschriftungen/", "bietenholz.info", 1);
header('Location: ['...] . getenv('HTTP_HOST') . '/beschriftungen/eingelogt.php');

If I remark out the header(), the cookie will be set correctely.
Any suggestions?

Xuefer

2:35 am on Jan 29, 2003 (gmt 0)

10+ Year Member



setcookie just don't work when u redirect by "Location:"
use meta/script redirect instead

andreasfriedrich

7:41 am on Jan 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com] marbi.

Be sure to read Marcia`s WebmasterWorld Welcome and Guide to the Basics [webmasterworld.com] post.

I´m not quite convinced that the combination of the Cookie and Location header field do not work together as Xuefer wrote. I´m using the following code on one site and it works just fine.

setcookie('hash', md5($form['password'])); 
header("Location: %%BASE_ADDRESS%%\r\n");
Check whether your cookie is set without the redirect. Once it works try using the Location header as well. Perhaps redirecting to a page accessed via http over ssl and setting a cookie causes the problem. I haven´t checked that.

Andreas

marbi

2:34 pm on Jan 29, 2003 (gmt 0)

10+ Year Member



Only the META-redirect works. I cannot set the cookie if header() is on! The page itself and the destination is over SSL (same problem without SSL). The META-solution is ok for me, but I'm wondering why the header() way don't work?

Xuefer

4:11 pm on Jan 29, 2003 (gmt 0)

10+ Year Member



it's not header() not work
it's just setcookie not work with header("Location: ..")
maybe browser(IE) skip processing cookies when it recieved a "Location:" header

andreasfriedrich

10:30 pm on Jan 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Most definately the browser does not skip processing cookies when it recieved a "Location:" header. I just tested it again using IE 6 and Opera 6 + 7. Setting a cookie and redirecting works just fine for me.

It would ne nice to know what others think on this problem.

Andreas

jatar_k

10:33 pm on Jan 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to the boards marbi

I am pretty sure I have done that exact thing with out problems so I am not sure what exactly is happening.

any other clues marbi? error messages, strange behaviours?

What is it exactly that you are doing to set a cookie and redirect, some type of tracking?