Cookies in PHP
To create cookies setcookie( ) method is used:
setcookie("name","usman" ,time( ) + (86400 * 30), "/");
Syntax:
setcookie(name, value, validity time, path, domain);
To retrieve value from cookies:
Example:
echo $_COOKIE['name'];
Syntax:
$_COOKIE['cookie name'];
To discard cookies:
set cookies expiry time 1 hour back
setcookie("name","usman" ,time( ) - (3600), "/");
setcookie("name","usman" ,time( ) - (3600), "/");
Download Code
index.php
<form action="#" method="POST" class="myform">
<input type="text" name="user" placeholder="Enter Your Name..." />
<input type="submit" />
</form>
<div class="myinfo">
<?php
if(isset($_COOKIE['uid'])){
echo "<h1>Your Name is : ".$_COOKIE['uid']."</h1>";
}
?>
</div>
new.php
Post a Comment