Escolar Documentos
Profissional Documentos
Cultura Documentos
What is a Cookie?
A cookie is often used to identify a user. A cookie is a small le that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
The setcookie() function is used to set a cookie. Note: The setcookie() function must appear BEFORE the <html> tag.
Note: The value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received (to prevent URLencoding, use setrawcookie() instead).
In the following example we use the isset() function to nd out if a cookie has been set:
The code above will register the user's session with the server, allow you to start saving user information, and assign a UID for that user's session.
Output:
Output:
You can also completely destroy the session by calling the session_destroy() function:
Note: session_destroy() will reset your session and you will lose all your stored session data.