How to Create a Cookie?
Syntax
setcookie(name, value, expire, path, domain);
<?php
setcookie("user", "Alex Porter", time()+3600);
?>
<html>
.....
You can also set the expiration time of the cookie in another way. It may be easier than using seconds.
<?php
$expire=time()+60*60*24*30;
setcookie("user", "Alex Porter", $expire);
?>
<html>
.....
In the example above the expiration time is set to a month (60 sec * 60 min * 24 hours * 30 days).
________________________________________________________
<?php
___________________________
<?php
Examples
In the example below, we will create a cookie named "user" and assign the value "Alex Porter" to it. We also specify that the cookie should expire after one hour:<?php
setcookie("user", "Alex Porter", time()+3600);
?>
<html>
.....
You can also set the expiration time of the cookie in another way. It may be easier than using seconds.
<?php
$expire=time()+60*60*24*30;
setcookie("user", "Alex Porter", $expire);
?>
<html>
.....
In the example above the expiration time is set to a month (60 sec * 60 min * 24 hours * 30 days).
________________________________________________________