php cookies variable code example

Example 1: php cookies

//Cookies
//Cookies are stored on the client side. cookies are not as secure as sessions
//and it is recommended that you use sessions as much as possible.
//save addional information as an array in a cookie
<?php
    $user = ['name' => 'Brad', 'email' => '[email protected]', 'age' = 35];

    $user = serialize($user);

    setcookie('user', $user, time() + (86400 *30));
    
    $user = unserialize($_COOKIE['user']);

    echo $user['name'];

Example 2: retrieving a cookie in php

$cookiename = $_COOKIE['COOKIE ID']

Example 3: php cookie

setcookie ('name', 'value', $expiresOn, $path, $domain, $secure, $httponly)

Example 4: cookies php syntax

setcookie("cookie_name", "type_on_cookie", expiry_time(), "/");

Tags:

Php Example