I am completely new to php development.
I have a php page where I am wanting to store a random value to a cookie. I have made the following code:-
---------------------------------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="testCookies.php" method="post">
<input type="submit" value="Test" id="btn_test" name="btn_test"/>
</form>
<?php
if (isset($_POST['btn_test']))
{
if(isset($_COOKIE["username"]))
{
}
if(!isset($_COOKIE["username"]))
{
$my_RANDOM=rand();
$expire=time()+10*5*1*0;
setcookie("username", "$my_RANDOM", $expire);
}
print ($_COOKIE["username"]);
}
?>
</body>
</html>
---------------------------------------------------------------------------------------------------------But the above code is not at all working.
Please let me know how to make this thing done and oblige me thereby.
Thanks.


Sign In
Create Account

Back to top









