I read that cookie values can be set after HTML content has been sent from a PHP script to the web server.
However, when working with this, I have not been able to set the cookies as I had hoped. Can someone straighten out my discrepancy?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHP can only set cookies while sending the headers of the page (that is, before sending the content – the HTML).
This is how the HTTP protocol works regarding cookies, the server can send a request to the browser to store cookies.
If you wish to add cookies after the page loaded, you can do it via JavaScript.