Cookies - Create, Access, Delete
are like name tags; You tell the server your name and it can give you a sticker to wear. Then it can know who you are by referring back to that name tag. ex.: setcookie('firstname', 'vins'); setcookie('user_id', 'linux'); Access Cookies To access use the $_COOKIE['value name'], along with the register_globals settings turn on in PHP. ex.: setcookie('username', 'larry'); $_COOKIE['username'] the sample code below show's, how to check for an existing cookie and as follows: ex.: IF ( !isset($_COOKIE['username'])) { header("location: http://". $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php"); exit(); } Delete or Remove a Cookie ex.: setcookie('firstname', ''); setcookie('firstname', '', time()-300); Cookie parameters syntax: setcookie('name', 'value', expiration, 'path', 'domain', secure); ex.: setcookie('name', 'value1', time()+3600);
|

