Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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