Home > PHP > Retrieving Cookie

Retrieving Cookie

Basis

If your cookie hasn’t expired yet, let’s retrieve it from the user’s PC using the aptly named $_COOKIE associative array. The name of your stored cookie is the key and will let you retrieve your stored cookie value!

Ex

<?php
if(isset($_COOKIE[‘lastVisit’]))
$visit = $_COOKIE[‘lastVisit’];

echo “Your last visit was – “. $visit;
?>

Outline

Here we have used isset function to be sure that our “lastVisit” cookie still exists on the user’s PC, if it does, then the user’s last visit is displayed.

Categories: PHP
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment