You can only overwrite cookies that you have access to change. If you set the cookie yourself using setcookie() , then the same function will overwrite this cookie.
Cookies must be modified before any data is sent to the browser. The browser identifies the cookie and saves it based on the headers sent from the server to the browser. The HTTP protocol will not accept header elements during body transfer.
source share