PHP Code To Set And Retrieve Cookie

Last updated on May 11th, 2016 at 02:07 pm

Click to rate this tutorial!
[Total: 0 Average: 0]

PHP Code To Set And Retrieve Cookie

I am going to create a cookie named userSetting a cookie using PHP
In the code below cookie is set to after expire 30 days [60*60*24*30] from the day it got created.

<?php
$expire=time()+60*60*24*30;
setcookie("user","John", $expire);
?>

Retrieve a cookie using php

<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
echo "Welcome guest!<br />";
?>

Very simple is it….enjoy!!!!!!!!!!!!!!

Click to rate this tutorial!
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published.