0

I have the following code. It works perfectly on a Localhost:

if(isset($_GET['vote']) AND isset($_GET['ididea']))
{
   setcookie($_GET['ididea'], $_GET['ididea'], time() + 365*24*3600, null, null, false, true);
}

And this is the error by the server:

Warning: Cannot modify header information - headers already sent by (output started at /home/sirobdco/public_html/index.php:15) in /home/sirobdco/public_html/includes/votetovote/includes/2/bodyvotetovote.php on line 4

And what I have on line 15?The first line of code in body:

<?php
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

You cannot set cookies after output is started. You must put the cookie section at the top of the script (before any output is done) or you must use ob_start() to buffer the output.

skrilled
  • 5,350
  • 2
  • 26
  • 48
  • Where i should use this? Before what? Thank you so much. – user2632603 Sep 25 '13 at 18:31
  • Assuming since the error is on line 15, that there is output being done before line 15. Output is any text that would display to the user. Even a tag would be enough to send headers. Anything dealing with cookies should happen before ANYTHING that could output to a user. Also nbd, hope this helps :) – skrilled Sep 25 '13 at 18:32
  • @user2632603 - if this answer helped you, please accept it as correct – andrewsi Sep 29 '13 at 03:32