Table of Contents
php creates, obtains cookies and analyzes basic points, phpcookie
Home Backend Development PHP Tutorial PHP creates, obtains cookies and analyzes basic points, phpcookie_PHP tutorial

PHP creates, obtains cookies and analyzes basic points, phpcookie_PHP tutorial

Jul 13, 2016 am 10:08 AM
cookie php

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

Copy code The code is as follows:
setCookie("name","Baidu",time()+60);
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

Copy code The code is as follows:
echo "
";
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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947919.htmlTechArticlephp creates, obtains cookies and basic key points analysis, phpcookie This article explains the analysis of php creation, obtaining cookies and basic key points. . Share it with everyone for your reference. The details are as follows: Assume that...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

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

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

See all articles