What is a cookie?
Cookies are often used to identify users. Cookies are small files that the server leaves on the user's computer. Whenever the same computer requests a page through a browser, it sends cookies as well. Through the PHP tutorial, you can create and retrieve the value of a cookie.
How do I create cookies?
The Setcookie () function is used to set cookies.
Note: the Setcookie () function must precede the
Grammar
Setcookie (name, value, expire, path, domain);
function Cookie ($var, $value = ', $time =0, $path = ', $domain = ') {
$_cookie[$var] = $value;
if (Is_array ($value)) {
foreach ($value as $k => $v) {
Setcookie ($var. ' [$k. '] ', $v, $time, $path, $domain, $s);
}
}else{
Setcookie ($var, $value, $time, $path, $domain, $s);
}
What if the browser does not support cookies?
If your application involves a browser that does not support cookies, you will have to take other steps to pass information from one page to another in your application. One way is to pass data from a form (for forms and user input, as we've already covered in this tutorial earlier).
The following form submits user input to "welcome.php" when the user clicks the Submit button:
<body>
<form action= "welcome.php" method= "POST"
Name: <in Put type= ' text ' name= ' name '/>
Age: <input type= ' text ' name= ' age '/>
<input type= ' submit '/>
&L T;/form>
</body>
<body>
Welcome <?php echo $_post["name";? >.<br/>
You are <?php echo $_post[' age ';?> years ol D.
</body>