The code below is a simple experiment.Here i am trying to create a name input form which will be set as a cookie in the browser.But it appears that it is not working at all.Where might be the problem here.I am a beginner in php.So,it would be great if someone point out the mistakes i have made
<?php
if(isset($_POST['name']) && !empty($_POST['name'])){
$cookie_value=$_POST['name'];
setcookie('user',$cookie_value, time() + 3600, '/');
}
?>
<html>
<body>
<?php
if(isset($cookie_value)&& !empty($cookie_value)) {
echo "user is".$cookie_value;
} else {
echo "Cookies are not set";
}
?>
<form action=<?php echo $_SERVER['PHP_SELF'] ?> method='post'>
<input type='text' name='text'>
<input type='submit' value='submit'>
</form>
</body>
</html>