A
A
Alexander Sharomet2016-08-15 21:29:34
PHP
Alexander Sharomet, 2016-08-15 21:29:34

How to use cookies correctly, why does it give an error?

Hello.
I have such a problem. When a user enters the site, I check the login and password, and if they match, then I create a cookie, but at this stage I get an error Warning: Cannot modify header information - headers already sent by (output started at. I understand that cookies are needed create at the very beginning of the code, but how can I do this if I create them after the user logs in. Is there something like startcookie, etc.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2016-08-15
@sharomet

Cookies can be created anywhere in the code, even on the penultimate line - as long as before any output to stdout.
The text of the error kindly indicates from what moment of execution the output began - after this moment, the headers can no longer be changed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question