Tutorial by Examples

A cookie is set using the setcookie() function. Since cookies are part of the HTTP header, you must set any cookies before sending any output to the browser. Example: setcookie("user", "Tom", time() + 86400, "/"); // check syntax for function params Description: ...
Retrieve and Output a Cookie Named user The value of a cookie can be retrieved using the global variable $_COOKIE. example if we have a cookie named user we can retrieve it like this echo $_COOKIE['user'];
The value of a cookie can be modified by resetting the cookie setcookie("user", "John", time() + 86400, "/"); // assuming there is a "user" cookie already Cookies are part of the HTTP header, so setcookie() must be called before any output is sent to the...
Use the isset() function upon the superglobal $_COOKIE variable to check if a cookie is set. Example: // PHP <7.0 if (isset($_COOKIE['user'])) { // true, cookie is set echo 'User is ' . $_COOKIE['user']; else { // false, cookie is not set echo 'User is not logged in'; } ...
To remove a cookie, set the expiry timestamp to a time in the past. This triggers the browser's removal mechanism: setcookie('user', '', time() - 3600, '/'); When deleting a cookie make sure the path and domain parameters of setcookie() matches the cookie you're trying to delete or a new cooki...

Page 1 of 1