Описание тега setcookie
The setcookie function sends an HTTP cookie to a client.
Setcookie () defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html>
and <head>
tags as well as any whitespace.