No puedo registrar la cookie, recibí un código de error sobre los encabezados [duplicado]
Frecuentes
Visto 44 veces
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
1 Respuestas
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.
Respondido el 25 de Septiembre de 13 a las 19:09
Where i should use this? Before what? Thank you so much. - user2632603
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 <!DOCTYPE html> 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
Oh i got is working!! Thank you - user2632603
@user2632603 - if this answer helped you, please accept it as correct - Andrewsi
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php sql cookies header or haz tu propia pregunta.
What's on lines 1-14 of that file? - andrewsi
it seems like your included file
bodyvotetovote.php
already makes someecho
's or other output. - Jay ClaitonSi tienes
<?php
in 15 line, you've also got many other chars in previous line. That's the problem. - Elon ThanYes guys bodyvotevote.php is include (using php) in index.php. Thats the problem what can i do to fix it? Thank you. - user2632603