MyBB Community Forums

Full Version: Cookie Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
This has nuthing to do with MyBB

Ok for the last week now I have been trying to figure out why my new server isn't saving cookies. I am using Xampp, I have used it befor but ever since I upgraded to

MySQL 5.0.15
Apache 2.0.55
OpenSSL 0.9.8a
PHP 5.0.5

Cookies wouldn't save with the
setcookie("blake_user", $user, time()+365);
function.
error Wrote:Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\blake\user.php:4) in C:\xampp\htdocs\blake\user.php on line 89

Every other softwear on my server, cookies work fine (Wordpress, MyBB) except for my home brewed Script. If any one could shed some light on this it would be greatly appreciated.
Mmm... cookies.

Back on topic, make that no code is printing anything to the page until the cookie (and other headers) have been set. It is generally a good idea to make sure that cookies are set at the very start of the execution of the called script. If it comes down to it, a work around may be used to issue all echoes to the end of the script using the ob_start();, ob_get_contents();, and ob_end_clean(); functions.
By any chance could you provide me with an example of what your talking about i don't realy follow. I'm a visual learner Toungue I can't place it at the top because the script will then not work correctly.
Would you mind providing a copy of the script then?
Ya sure I'll include the main page, my functions file and the users file. the user file has the cookies in it.
I need to see the user.php file too.
updated
Try this file.
Omg thank you so much Incendium work great just one littel bug to fix in my coding! thanks alot!
Buffers can be a handy tool when trying to manipulate headers. An alternative to the way I gave you so that you could manipulate the final text before it outputs is to replace:

ob_end_flush();
with
$content = ob_get_contents();
ob_end_clean();

// Manipulate $content here

echo ($content);

This way, you can run functions and manipulate the final output of the page.
Pages: 1 2