management snippets

How to set a cookie, remove a cookie and get the value of a cookie in PHP

Tagged php, cookie, management, set, remove, get  Languages php

PHP cookie management is a good example of how incredibly badly designed PHP is:

Set a cookie that expires when browser is closed

Note that you most probably want to set the path, which we do here:

$value = 0;
$expires = 0;
setcookie('cookie_name', $value, $expires, '/');

Remove cookie

setcookie ('cookie_name', FALSE, time()-10000);

Get cookie value

$_COOKIE['cookie_name']