I have a problem with my site that worked fine until recently: cookies are not saved in any browser I’ve tested, that includes session cookies.
To isolate and identify the problem, I created a php file making sure there is no output before “session_start ();” or “setcookie ();”, but the problem continues (it seems that the server itself was sending some output before running the php file, I can not think of another reason)
But I did not understand why I needed to control the output using a buffer, in my code there was no output before starting session or setting cookies; Does the http server add some output automatically before running my script? … Given the solution I suppose yes, but I would like to know which one and why
But I did not understand why I needed to control the output using a buffer, in my code there was no output
session_start(); should be placed in top of the script because it’s using cookies to identify the clients. Therefore using setcookie() before session_start() might interfere.
Does the http server add some output automatically before running my script?
No, it doesn’t
$bufer = (setcookie(‘prueba’,‘lista’))?‘Cookie establecida correctamente’:‘No se pudo establecer la cookie’;
I don’t know if it only sets the value to $bufer or it also outputs it. I have never tested it in such way.
Je je, I had already tested with session start before set cookie or any other code and the result was the same; until today I had the suspicion that it was a specific problem of cookies and I added set cookie to prove it. That’s why I sent the query.
Either way the buffer solved the problem, thanks again.