php validate cookie code example
Example 1: php cookies
<?php
$user = ['name' => 'Brad', 'email' => '[email protected]', 'age' = 35];
$user = serialize($user);
setcookie('user', $user, time() + (86400 *30));
$user = unserialize($_COOKIE['user']);
echo $user['name'];
Example 2: php cookies
<?php
if(isset($_POST['submit'])){
$username = htmlentities($_POST['username']);
setcookie('nameofcookie', $username, time()+3600);
header('Location: page2.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP Cookies</title>
</head>
<body>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="text" name="username" placeholder="Enter Username">
<br>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</body>
</html>