


PHP creates, obtains cookies and analyzes basic points, phpcookie_PHP tutorial
php creates, obtains cookies and analyzes basic points, phpcookie
This article analyzes PHP creation, obtaining cookies and basic points with examples. Share it with everyone for your reference. The details are as follows:
Assume: cookie1.php file
echo "Save cookie";
?>
There are three required parameters:
(1) The first parameter: name is the key value, set it yourself;
(2) Second parameter: "Baidu" in the example represents the value corresponding to the key value name;
(3) The third parameter: indicates the expiration time, time()+60, which indicates the expiration time is 60 seconds;
Cookie code analysis and basic points in the example
1. When the browser opens cookie1.php, the server will send the message: Set-Cookie:name=%B0%D9%B6%C8; expires=Tue, 06-Nov-2012 16:09:27 GMT (Remarks : Please use the packet capture tool to view this information) to respond to the http request. The client browser obtains this information and saves it in the cookie file (different browsers and operating systems have different storage locations and file types)
2. If the third time parameter is not set, the cookie will expire when the session ends (close the browser) by default (in this case, the cookie is stored in the browser cache).
3. Cookies can only save string information, that is, objects cannot be saved (session can save objects).
4. If the key value is Chinese, the urlencode method is used by default to transcode the Chinese.
5. When the cookie is saved, it is saved in clear text, so the password needs to be processed, such as md5.
6. Multiple cookies can be saved.
7. Different cookies on the same page can be saved for different times.
8. A website corresponds to a file that saves cookies (if cookies are set).
Get cookies
File: cookie2.php
";
print_r($_COOKIE);
echo $_COOKIE['name'];
?>
$_COOKIE is a predefined variable (array). During the validity period of the cookie, the above code can be used to output the cookie.
Knowledge points: When the browser accesses the cookie2.php page, it will transmit the cookie information to the server. This is stipulated by the http protocol (you can use the packet capture tool to view it, as shown below)
I hope this article will be helpful to everyone’s PHP programming design.

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

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
