


Usage analysis of cookie method in thinkphp3.x, thinkphp3.xcookie_PHP tutorial
Usage analysis of cookie method in thinkphp3.x, thinkphp3.xcookie
This article analyzes the usage of cookie method in thinkphp3.x with examples. Share it with everyone for your reference, the details are as follows:
1. The cookie function is also a diversified operation function that completes the setting, acquisition and deletion of cookies.
Cookie is used for cookie setting, retrieval, and deletion operations:
Usage:
cookie($name, $value='', $option=null)
Parameters:
name (required): cookie variable to be operated
value (optional): cookie value to be set
option (optional): Incoming cookie setting parameters, empty by default
Return value See details (returns different values according to specific usage)
2. Cookie settings
cookie('name','value'); //设置cookie cookie('name','value',3600); // 指定cookie保存时间
Starting from version 3.1, the cookie method adds support for arrays (saved in lightweight json encoding format to reduce storage space), for example:
cookie('name',array('name1','name2'));
You can also complete complex cookie assignments by passing in parameters. The following is to set the validity period of 3600 seconds for the cookie value, and add the cookie prefix think_
cookie('name','value',array('expire'=>3600,'prefix'=>'think_'))
Array parameters can take the form of query parameters
cookie('name','value','expire=3600&prefix=think_')
Equivalent to the above usage.
The option parameter passed in supports the four index parameters of prefix, expire, path and domain. If no or null value is passed in, the four configuration parameters COOKIE_PREFIX, COOKIE_EXPIRE, COOKIE_PATH and COOKIE_DOMAIN will be taken by default. If only individual parameters are passed in, they will also be merged with the default configuration parameters.
3. Cookie acquisition
Getting cookies is very simple. No matter how you set the cookie, you only need to use:
$value = cookie('name');
If no cookie prefix is set, it is equivalent to
$value = $_COOKIE['name']
If the cookie prefix is set, it is equivalent to
$value = $_COOKIE['前缀+name']
4. Cookie deletion
To delete the value of a cookie, use:
cookie('name',null);
To delete all cookie values, you can use
cookie(null); // 清空当前设定前缀的所有cookie值 cookie(null,'think_'); // 清空指定前缀的所有cookie值
PS: Here are several formatting and beautification tools recommended for this site. I believe everyone can use them in future development:
php code online formatting and beautification tool:
http://tools.jb51.net/code/phpformat
JavaScript code beautification/compression/formatting/encryption tool:
http://tools.jb51.net/code/jscompress
Online XML formatting/compression tool:
http://tools.jb51.net/code/xmlformat
JSON code formatting and beautification tool:
http://tools.jb51.net/code/json
Online XML/JSON conversion tool:
http://tools.jb51.net/code/xmljson
SQL code online formatting and beautification tool:
http://tools.jb51.net/code/sqlcodeformat
Readers who are interested in more thinkPHP-related content can check out the special topics on this site: "Introduction to ThinkPHP Tutorial", "Summary of Common Methods of ThinkPHP", "Summary of Cookie Usage in PHP", "Basic Tutorial for Getting Started with Smarty Templates" and "PHP Template technology summary".
I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.
