nvidia Posted January 23, 2008 Share Posted January 23, 2008 Hi, i have set a cooke using the following code: cookies.php <html> <head> <title>Forms</title> </head> <body> <?php // time(60 seconds in 1min,60 minutes in 1hr,24hrs in a day, 7days a week), it will expire in 1 week from now setcookie('test', 45, time()+(60*60*24*7) ); ?> </body> </html> but when i view this on my web browser[iE], i get the error message warning message saying Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\php_sandbox\cookies.php: in C:\wamp\www\php_sandbox\cookies.php on line 10. Would somebody tell me how to over come this please. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/ Share on other sites More sharing options...
interpim Posted January 23, 2008 Share Posted January 23, 2008 change it and take out everything except your php code... put your setcookie() on the very first line of code Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-446499 Share on other sites More sharing options...
nvidia Posted January 23, 2008 Author Share Posted January 23, 2008 Hi thanks for your quick response. I have removed everything even the html code to be left with: <?php setcookie('test', 45, time()+(60*60*24*7));?> but i still get the message of Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\php_sandbox\cookies.php: 3) in C:\wamp\www\php_sandbox\cookies.php on line 3. Even with the HTML code, it should work right?? Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-446502 Share on other sites More sharing options...
interpim Posted January 23, 2008 Share Posted January 23, 2008 are you calling this script from another page? Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-446507 Share on other sites More sharing options...
jambroo Posted January 23, 2008 Share Posted January 23, 2008 Try this from http://au2.php.net/manual/en/function.setcookie.php: <? header("Content-Type: text/html; charset=utf-8"); setcookie("aaa", "bbb"); ?> <html> <head> ... Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-446509 Share on other sites More sharing options...
interpim Posted January 23, 2008 Share Posted January 23, 2008 well... the problem is when you use setcookie() it sends a header, so if you are calling it from another script that writes anything else to the screen then it will give that error unless you use output buffering... That script by itself shouldn't give that error, but if you are calling it from another script that you expect output from you will get that error... output buffering can be turned on in the script you call your setcookie from by putting ob_start(); at the beginning of the script and then an ob_end_flush(); at the end. But there are some disadvantages to this primarily concerning security... Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-446513 Share on other sites More sharing options...
revraz Posted January 23, 2008 Share Posted January 23, 2008 Stickies are your friend http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-446541 Share on other sites More sharing options...
hamza Posted January 24, 2008 Share Posted January 24, 2008 good PIECE OF ADVICES as MY FRINED SAID PLACE YOUR COOKIE ON FIRST LINE. AND ABOUT BUFFER YOU CAN SET THE BUFFER IN TWO WAYS FROM PHP.INI FILE OR YOU CAN USE THE START_OB(); OR GO TO PHP.NET FOR MORE BUFFER INFORMATION IF STILL YOU HAVE ANY PROBLEM THEN SEND ME YOU ALL CODE OR ONE THING MORE PLACE YOUR COOKIE IN YOUR HEADER NOT IN YOUR BODY Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-447639 Share on other sites More sharing options...
nvidia Posted January 24, 2008 Author Share Posted January 24, 2008 Ok cool, i'll have a look at that, i WILL definitely get back to you in a few days or two, thanks everybody, and Hamza. Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-448158 Share on other sites More sharing options...
nvidia Posted January 27, 2008 Author Share Posted January 27, 2008 Hi just managed to solve it, i had blank spaces before my starting php tags. Thanks everybody, happy days. Quote Link to comment https://forums.phpfreaks.com/topic/87294-cookie-problem/#findComment-450708 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.