I made an input form when the user types in a name. a isset($_COOKIE) checks if the made cookie already exists. if the cookie exists you'll get a message: Welcome back. if not you'll get the message: this is your first time here. but somehow i always get the message welcome back.
Here is my code:
<?php
if(!empty($_POST))
{
header("Location:form_data.php");
setcookie('name',$_POST['name'], time() + (86400 * 30));
}
if(isset($_COOKIE['name']))
{
echo "Welcome back ".$_COOKIE['name'];
}else
{
echo "hello ".$_COOKIE['name']; echo " this is your first time here.";
setcookie('name',$_POST['name'], time() + (86400 * 30));
}
?>
can someone help me with this problem?