Thursday, December 16, 2010

Cookie

Creating a cookie
<?php
$expire=time()+60*60*24*30;
setcookie("user", "Alex Porter", $expire);
?>

Handling a cookie
<?php
    if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
    else
        echo "Welcome guest!<br />";
?>

Deleting a cookie
<?php
    setcookie("user", "", time()-$expire); //setting a past time
?>

No comments:

Post a Comment