Lotusphp's Cookie component is also very easy to use.
First of all, to create a new configuration file, the file name is cookie.conf.php, as to where to wait until the Config component, there will be a description, today first how to use, what steps are required.
The main content of the cookie configuration file is to define the encryption key of the cookie, the program automatically encrypts the cookie content, of course, there is a disadvantage, that is, the client can not directly read and operate, only the server to operate. If you want to use JS directly in the client to manipulate cookies, it is best not to use the lotusphp cookie component.
The key can be any character, and the contents of the configuration file are as follows:
Copy the Code code as follows:
$config [' cookie.secret_key '] = ' sdfs445e22$$$@%t ';
The components are used in the following ways:
Copy the Code code as follows:
Singleton schema declaration Cookie Object
$cookie = Ltobjectutil::singleton (' Ltcookie ');
Or declare the Cookie object in the usual way
$cookie = new Ltcookie ();
$cookie->init ();
/*
* Write a cookie, the way to set the cookie is actually the same as PHP built-in Setcookie
* $name Cookie name, required
* $value Cookie value, can be a string can be an array
* $expire Expiration time, is a standard Unix time stamp, which can be obtained in seconds () or mktime () function, optional
* $path Cookie path, optional
* $domain cookie domain name, optional, if you share a cookie between multiple two-level domain names, you can set it as the root domain.
* $secure parameter Indicates whether this cookie is transmitted over the network via an encrypted HTTPS protocol, and the default value is 0, which means that the HTTPS protocol is not used, and if so it is changed to 1
* Method: $cookie->setcookie ($name, $value = ", $expire = null, $path = '/', $domain = null, $secure = 0);
* Example: UserName value for ' I am handsome ', valid for one hours, path is root directory, domain name is mydomain.com, not transmitted under HTTPS
* $cookie->setcookie (' userName ', ' I'm Handsome ', Time () +3600, '/', ' mydomain.com ', 0);
*/
$cookie->setcookie (' userName ', ' I'm Handsome ');
/*
* Read cookies
* $name Cookie name, required
* Method: $cookie->getcookie ($name);
* Returns a value if a Cookie value exists, does not exist return null
*/
$cookie->getcookie (' userName ');
/*
* Delete Cookies
* $name Cookie name, required
* $path Cookie path, optional
* $domain cookie domain name, optional, if you share a cookie between multiple two-level domain names, you can set it as the root domain.
* Method: $cookie->delcookie ($name, $path = '/', $domain = null)
*/
$cookie->delcookie (' userName ');
Finally, attached to the PHP operation Cookie article, you can control, in fact lotusphp set cookie and PHP settings cookie is the same
Workaround for setting, using, and deleting cookies in PHP
http://www.bkjia.com/PHPjc/327030.html www.bkjia.com true http://www.bkjia.com/PHPjc/327030.html techarticle Lotusphp's Cookie component is also very easy to use. First of all, to create a new configuration file, the file name is cookie.conf.php, as to where to wait until the Config component will ...