Lotusphp notes: The use of cookie components _php examples

Source: Internet
Author: User
Tags setcookie

The lotusphp Cookie component is also very easy to use.

First, to create a new profile, the file name is cookie.conf.php, and there will be a description of where to wait for the Config component, and what steps to use today.

The main content of the cookie configuration file is to define the encryption key of the cookie, the program automatically encrypt the contents of the cookie, 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 on the client to operate 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 Code code as follows:

<?php
$config [' cookie.secret_key '] = ' sdfs445e22$$$@%t ';

The components are used as follows:
Copy Code code as follows:

<?php
Single-case mode Declaration Cookie Object
$cookie = Ltobjectutil::singleton (' Ltcookie ');

Or declare a Cookie object in a normal way
$cookie = new Ltcookie ();
$cookie->init ();

/*
* Write cookies, the way to set cookies is actually the same as the 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 tag, can be obtained with the mktime () function, in seconds, the optional
* $path Cookie Path, optionally fill
* $domain cookie domain name, optional, if multiple level two domain name sharing cookies, set to root domain name can be
* $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 is ' I am handsome ', valid for one hours, the path is the root directory, the domain name is mydomain.com, does not transmit under the HTTPS
* $cookie->setcookie (' userName ', ' I am Handsome ', time () +3600, '/', ' mydomain.com ', 0);
*/
$cookie->setcookie (' userName ', ' I'm a handsome man ');

/*
* Read cookies
* $name Cookie name, required
* Method: $cookie->getcookie ($name);
* If the Cookie value exists returns a value, there is no return null
*/
$cookie->getcookie (' userName ');

/*
* Delete Cookies
* $name Cookie name, required
* $path Cookie Path, optionally fill
* $domain cookie domain name, optional, if multiple level two domain name sharing cookies, set to root domain name can be
* Method: $cookie->delcookie ($name, $path = '/', $domain = null)
*/
$cookie->delcookie (' userName ');


Finally, with the PHP operation Cookie article, we can control, in fact, lotusphp set cookies and PHP settings cookie is the same

workaround for setting, using, and deleting cookies in PHP

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.