How to set Cookie Using PHP

04th, January 2018 By

Today we will check how set cookie in php.cookie is stored in client side, not on server side.We will temporary store value using cookie for our functions.Its very easy to set cookie in php.

<?php   //setting a cookie
   $country = "India";
   $expiry_period = time() + (86400 * 7)); // 86400 = 1 day
   setcookie('country',$country,$expiry_period);
?>

Now your cookie is set ,you will get the value of this cookie by using variable $_cookie[].

<?php

//getting a cookie
   $country_value = $_COOKIE['country'];

 ?>

Hope this will help you.

Leave a Reply

Your email address will not be published. Required fields are marked *