PROGRAMMING

  MINTE9
REMEMBERS




Last update:   29-10-2021

Cookies

Allows your application to store a small text file on client Web browser. If you want to set cookie for another domain, it can not be done.
 
setcookie('hide_menu', '1'); // Set a cookie on the client
setcookie('hide_menu', '1', 3600); // expiration time - 1 hour

if ($_COOKIE['hide_menu'] == 1) {
    echo 'Hide Menu';
}

Values

Cookies values must be scalar, not arrays. To delete a cookie, set time negative.
 
setcookie('hide_menu', array()); //expects parameter 2 to be string
 
setcookie("hide_menu", false, -3600);
You can create cookie arrays using the same array. Keep in mind that the amount of storage available is severely limited, use sessions instead.
 
setcookie('test[0]', "foo");
setcookie('test[1]', "bar");

Arguments

You can set different cookie arguments.
 
setcookie('hide_menu', '1', 86400, '/path/', 'www.example.com', 1); 

    // where cookie will be accesible - path
    // allowed domain
    // the browser can only send cookie in case of HTTPS
    // expiration time one day

Questions    
Sessions
        A B C D E F
🔔
1/5