PDA

View Full Version : Setting a cookie?


Tim Mousel
Wed 2nd Oct '02, 2:39am
Where do I place my setcookie code if I want to set a cookie when someone visits the index page?

I'm having problems with header already being sent errors, so I'm obviously placing my code in the wrong place.

Please help!

Chen
Wed 2nd Oct '02, 10:52am
You must call setcookie() before you send any output to the browser. If that's not possible, consider using output buffering:

<?php

echo "I'm printing stuff";

// Yet I can set a cookie
setcookie('cookieName', 'value');

// Before output is kept in the buffer and not sent to the browser
ob_end_flush();

?>