PHP Code Explanation 2

<?php
$cookie_name = "user";
$cookie_value = "John Doe";
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 "Value is: " . $_COOKIE[$cookie_name];
}
?>

</body>
</html>
  • – The code sets a cookie named “user” with the value of “John Doe”.
  • – The code then prints out the value of this cookie.
  • – The code sets a cookie named “user” with the value of “John Doe”.
  • – The time() + (86400 * 30) is set to 86400 = 1 day.

Leave a Comment