PHP Example | Set Cookie and Get Cookie Value

This php example code will show us how to set and get cookie value in web development.

Set cookie value

$first_name = 'Tom';
setcookie('first_name',$first_name,time() + (86400 * 7)); // 86400 = 1 day

Get cookie value

echo 'Hello '.($_COOKIE['first_name']!='' ? $_COOKIE['first_name'] : 'Guest'); // Hello Tom!