/* include $_SERVER[‘DOCUMENT_ROOT’] . ‘/cookies.php’;*/
header(‘Location: /cookies.php’);
exit();
Cookies.php is a simple page that just echos out variable values. When I uncomment and use the include to go to cookies.php, it echos out all the variable values just fine. When I use the header to go to that page, it doesn’t echo out any of the variables, including $_SESSION and $_COOKIE variables. Why is it that when I use header, I lose all my variable values?
For anyone interested, I was using Notepad++ to do the coding. There is an option in there to Encode the document with UTF-8 without BOM. When that is selected the problem goes away.
Immerse, actually you can set cookies like that for local use. It doesn’t change the value of the cookie on the users machine but will change the value on the server. On the first posting I made above, you will see that I use setcookie() and then assign the cookie value locally because it won’t be refreshed on the server until another page is called.
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\htdocs\cookies.php:1) in C:\htdocs\cookies.php on line 1
Also, as a matter of best practice, what is the difference between header and include in this case and which one should be used, i.e. when should you use header and when should you use include to get to another page.
No, it’s on line 1 and there are no spaces before it. Could it be something from the page that is calling it as a header? Or I am assuming once I issue the header(location:… command it clears the headers, correct?
This is a copy of the code and it is all left justified.
No matter where I put the session_start() in the cookies.php file, I get the message
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\htdocs\cookies.php:3) in C:\htdocs\cookies.php on line 4
And yes I tried it at the very top of the file, inside the php script with the echos, and where it is now and I get the same message all the time. Good news is I do get the session variable values now showing up but still not the cookie values.