Sunday, 1 February 2015

Cookies

Normally cookie use to identify users . Cookie is file which save on client/user system , from where we can fetch info
syntax for cookie setcookie(name, value, expire)
Example:

<!DOCTYPE html>
<?php
$cookie_name = "your_user";
$cookie_value = "php guides";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30)); // 86400 = 1 day
?>
<html>
<body>

<?php
if(!isset($_COOKIE[$cookie_name])) {
      echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
      echo "Cookie '" . $cookie_name . "' is set!<br>";
      echo "Your Cookie Value is: " . $_COOKIE[$cookie_name];
}
?>

<p style="color:red">If You Don't See value reload to see cookie value</p>

</body>
</html>


Output Print



No comments: