Jump to content

Another Warning: cannont modify header info


Ogdan

Recommended Posts

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.

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>....

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.