What's wrong with my code? When I run it, it tells me: "Notice: Undefined index: visits" on the lines if($_COOKIE["visits"] == 1)
and $numOfVisits = $_COOKIE["visits"];
in the body section.
<!DOCTYPE html>
<?php
if (!isset($_COOKIE["visits"]))
setcookie("visits", 1, time()+3600*24*365);
else{
$visits = $_COOKIE["visits"] + 1;
setcookie("visits",$visits, time()+3600*24*365);
}
?>
<html lang="en">
<head>
<title>numOfVisits</title>
<meta charset="utf-8"/>
</head>
<body>
<?php
if($_COOKIE["visits"] == 1)
echo("Welcome to my webpage! It is your first time that you are here.");
else{
$numOfVisits = $_COOKIE["visits"];
echo("Hello, this is the #$numOfVisits time that you are visiting my webpage.");
}
?>
</body>
</html>