- The variable name
- The variable value
- The length of time the cookie should be saved on the PC for reuse (the example shows 180 days)
- The domain path for which the cookie is available - for the whole domain use /
- The domain name
Code: Select all
<?php
$cookieCount = 0;
if (isset($_COOKIE['visitcount'])) $cookieCount = $_COOKIE['visitcount'];
$cookieCount++;
setcookie("visitcount",$cookieCount,time()+60*60*24*180,'/','.yourdomain.com');
if ($cookieCount > 1) echo "Welcome back. You have been here $cookieCount times.";
?>