Ogdan Posted January 20, 2010 Share Posted January 20, 2010 OK, so i have been looking all over the web for the answer to this and I just cant find it. All im trying to do is get setcookie() to work <html> <head> <title>cookies</title> </head> <body> <?php setcookie('test', 11, time()+(60*60*24*7)); ?> </body> </html> nothing special but i still come up with an error. I am just wondering why this wont work and whats wrong with the "timing" of it. any help would be great. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/189104-another-warning-cannont-modify-header-info/ Share on other sites More sharing options...
co.ador Posted January 20, 2010 Share Posted January 20, 2010 uch!! I just had that error a couple of hours ago! setcookie(); and hearder(); functions can not be used after <html> output <html> <head> <title>cookies</title> </head> <body> <?php setcookie('test', 11, time()+(60*60*24*7)); ?> </body> </html> In the code above you have it inside the html tags, Take the function and put it above the html output tags <?php setcookie('test', 11, time()+(60*60*24*7)); ?> <html>.... Quote Link to comment https://forums.phpfreaks.com/topic/189104-another-warning-cannont-modify-header-info/#findComment-998377 Share on other sites More sharing options...
Ogdan Posted January 20, 2010 Author Share Posted January 20, 2010 Ahh ha, thank you so much, and there really can be nothing before those function calls eh? It was weird because in the tutorial that i was watching he was able to do it just the way that I had originally done it with no problems. I wonder if it was an old version of PhP or what? anyway thank you very much for the help. ps. im not sure how to show this as solved but it is. thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/189104-another-warning-cannont-modify-header-info/#findComment-998538 Share on other sites More sharing options...
PFMaBiSmAd Posted January 20, 2010 Share Posted January 20, 2010 It was weird because in the tutorial that i was watching he was able to do it just the way that I had originally done it with no problems. I wonder if it was an old version of PhP or what? It worked in that case because output_buffering was turned on in the master php.ini, so it was possible to create code that resulted in an incorrectly formed web page but functioned on the server where it was created. Unfortunately, php.net has a history of trying to get php to - "help a few beginners blissfully and unknowingly write better code." (quote taken directly from the php.net documentation.) This however means that the resulting code is not general purpose and prevents it from working on all servers and the people posting tutorials should be aware of special conditions like this and write tutorials that are correct that would work on all server configurations. Quote Link to comment https://forums.phpfreaks.com/topic/189104-another-warning-cannont-modify-header-info/#findComment-998624 Share on other sites More sharing options...
Ogdan Posted January 20, 2010 Author Share Posted January 20, 2010 So its not just my computer or my php, you would have to have the setcookie() and hedder() function calls at the top normally. That is good to know than you all for your help. Quote Link to comment https://forums.phpfreaks.com/topic/189104-another-warning-cannont-modify-header-info/#findComment-998888 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.