A cookie is a piece of data that is stored in the client’s web browser and used to identify your computer as you use a computer network.
A cookie can be set using PHP’s setcookie() function.
1 2 3 | <?php setcookie('car', 'Mercedes'); ?> |
How to read cookies in PHP
Getting Cookie in PHP we have to use the Global variable $_COOKIE[]
.
1 2 3 | <?php echo $_COOKIE['car']; ?> |
1 2 3 4 5 6 7 8 9 10 11 | <?php $name = 'car'; $value = 'Mercedes'; $expire = time() + 60*60*24*3; // 3 days from now $path = '/tutorials'; $domain = 'www.freeonlinetest.in'; $secure = isset($_SERVER['HTTPS']); // or use true/false $httponly = true; setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); ?> |