Answer the question
In order to leave comments, you need to log in
Why cookies can only be created at the beginning?
Why did they make this restriction? I always encounter problems associated with this, but I have not found any pluses for 2 years of work. Just wondering why they did it anyway?
Answer the question
In order to leave comments, you need to log in
First you need to understand what cookies are. How cookies are passed to the client. What are the headers and body of HTTP requests and responses. And then everything will fall into place. Well, so that there would be no problems - read about managing output buffering in PHP.
How are cookies different from a session in PHP?
In addition to Sergey Protko 's answer , I will say that you can create them at any time. But to install (send) - only before sending the response body.
By the way, things like the Symfony HTTPFoundation and PSR-7 are partly made to avoid shooting yourself in the foot like this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question