LotusPhp Notes: Detailed Explanation of the Use of Cookie Component_PHP Tutorial

WBOY
Release: 2016-07-21 15:10:53
Original
938 people have browsed it

LotusPhp’s Cookie component is also very simple and easy to use.

First of all, you need to create a new configuration file. The file name is cookie.conf.php. As for where to put it, I will explain it when I talk about the Config component. Today I will talk about how to use it and 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, this has a drawback, that is, the client cannot directly read and operate it, and can only be operated by the server. If you want to directly use js to operate Cookie on the client, it is best not to use LotusPhp's Cookie component.

The key can be any character. The content of the configuration file is as follows:

Copy code The code is as follows:

$config['cookie.secret_key'] = 'sdfs445e22$$$@%T';

The usage of the component is as follows:
Copy code The code is as follows:

// Singleton mode declares Cookie object
$cookie = LtObjectUtil::singleton('LtCookie' );

// Or declare the Cookie object in the usual way
// $cookie = new LtCookie();
// $cookie->init();

/*
* Write Cookie. The method of setting Cookie is actually the same as PHP's built-in setcookie
* $name Cookie name, required
* $value Cookie value, can be The string can be an array
* $expire expiration time, which is a standard Unix time stamp, which can be obtained using the time() or mktime() function, in seconds, optional
* $path Cookie path, Optional
* $domain Cookie domain name, optional. If cookies are shared between multiple second-level domain names, just set it as the root domain name
* $secure parameter indicates whether this cookie is on the network through the encrypted HTTPS protocol Upload transmission, the default value is 0, which means the HTTPS protocol is not used, if so, change it to 1
* Method: $cookie->setCookie($name, $value = '', $expire = null, $path = '/', $domain = null, $secure = 0);

* Example: userName value is 'I am a handsome guy', valid for one hour, path is root directory, domain name is myDomain.com, not transmitted under HTTPS
* $cookie->setCookie('userName', 'I am a handsome guy', time()+3600, '/', 'myDomain.com', 0);
*/
$cookie->setCookie('userName', 'I am a handsome guy') ;

/*
* Read Cookie
* $name Cookie name, required
* Method: $cookie->getCookie($name);
* If the Cookie value exists Return value, if it does not exist, return null
*/
$cookie->getCookie('userName');

/*
* Delete Cookie
* $name Cookie name, required
* $path Cookie path, optional
* $domain Cookie domain name, optional, if there are multiple To share cookies between level domain names, just set it as the root domain name
* Method: $cookie->delCookie($name, $path = '/', $domain = null)
*/
$cookie->delCookie('userName');


Finally, here is an article on how to operate Cookies in PHP. You can check it. In fact, setting Cookies in LotusPhp and setting Cookies in Php are the same

Solutions to setting, using and deleting cookies in PHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327030.htmlTechArticleLotusPhp’s Cookie component is also very simple and easy to use. First of all, we need to create a new configuration file. The file name is cookie.conf.php. As for where to put it, we will wait until we talk about the Config component...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!