Lotusphp notes: The use of cookie components _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.