Ukážka použitia cookies v PHP
<?php /** * @author sczdavos * @site www.itnetwork.cz */ header('Content-type: text/html; charset=utf8'); if (isset($_GET['cookies'])) { if ($_GET['cookies'] == 'set') { setcookie("infinity", "never-expire", time() + (20 * 365 * 24 * 3600)); setcookie("time", "expire in: " . date('h:i:s d.m.Y', mktime(1, 2, 3, 4, 5, 2013)), mktime(1, 2, 3, 4, 5, 2013)); setcookie("thirty-seconds", "expire in 30 seconds" , time() + 30); } else if ($_GET['cookies'] == 'del') { foreach ($_COOKIE as $n => $cookie) setcookie($n, "expired", time() - 3600); } header('Location: ' . $_SERVER['SCRIPT_NAME']); } echo('Infinity: ' . $_COOKIE['infinity'] . '<br />' . 'Thirty-seconds' . $_COOKIE['thirty-seconds'] . '<br />' . 'Time' . $_COOKIE['time']); echo('<p><a href="cookies.php?cookies=set">Set this cookies</a> | <a href="cookies.php?cookies=del">Del all cookies</a></p>');
<?php /** * @author sczdavos * @site www.itnetwork.cz */ header('Content-type: text/html; charset=utf8'); if (isset($_COOKIE['views'])) $views = $_COOKIE['views']; else $views = 0; setcookie("last-seen", time()); setcookie("views", $views + 1); echo('Views: ' . $_COOKIE['views'] . '<br />' . 'Last-seen: ' . date('h:i:s d.m.Y', $_COOKIE['last-seen']));