Memory App
 




Cookies allow your application to store a small text file on client Web broweser.

<?php
    // Set a cookie on the client
    setcookie('hide_menu', '1');

    if ($_COOKIE['hide_menu'] == 1) {
        echo 'Hide Menu';
    }
?>
You can provide an expiration time.

<?php
    setcookie('hide_menu', '1', 3600); // 1 hour
?>
Cookies values must be scalar

<?php
    setcookie('hide_menu', array());
    // Warning: setcookie() expects parameter 2 to be string
There are three more arguments:

<?php
    // path - where cookie will be accesible
    // domain - allowed domani
    // secure - the browser only send cookie in case of HTTPS
    
    setcookie('hide_menu', '1', 86400, '/path/', 'www.example.com', 1); // a day
?>
You can create arrays using the same array.

<?php
    setcookie('test[0]', "foo");
    setcookie('test[1]', "bar");
To delete a cookie, set time negative

<?php
    setcookie("hide_menu", false, -3600);
Keep in mind that the amount of storage available is severely limited therefore, use sessions instead. If you want to set cookie for another domain, it can not be done.

Questions
0/0 (80)  
Not Logged