Home Backend Development PHP Tutorial Detailed explanation of COOKIE support in PHP4_PHP tutorial

Detailed explanation of COOKIE support in PHP4_PHP tutorial

Jul 21, 2016 pm 04:06 PM
cookie Function Business Establish support Compare site Detailed explanation

Detailed explanation of COOKIE support in PHP4

When establishing a commercial website or a personal website with relatively complete functions, it is often necessary to record visitor information. PHP provides two convenient means: session and cookie functions. In order to maintain it permanently User information, cookies are the most convenient way. Here I will explain the functions and usage of cookies in detail.

1: Set cookies
Cookies must be set before using cookies.
Function prototype: int setcookie(string name, string value, int expire, string path, string domain, int secure)
Among them, except name, all parameters are optional, and an empty string can be used to indicate Settings.
Attribute value: used to specify the value.
Attribute path: used to specify the directory path where the cookie is sent to the server.
Attribute domain: can be used to send cookies on the browser side Limited.
expire parameter: used to specify the validity time of the cookie, which is a standard Unix time stamp.
It can be obtained using the time() or mktime() function, in seconds.
secure parameter : Indicates whether this cookie is transmitted over the network through the encrypted HTTPS protocol.

2: Things to note when setting cookies
Setting cookies on the same page is actually in order from back to front Performed. If you want to delete a cookie first and then write a cookie, you must write the write statement first and then the delete statement. Otherwise, an error will occur.

Three: setcookie example
Simple: setcookie("mycookie","value_of_mycookie");
With expiration time: setcookie("withExpire","Expire_in_1_hour",time()+3600);
It has everything: setcookie("FullCookie", "Full_cookie_value",time+3600,"/forum","www.123.com",1);

Four: Some characteristics of cookies
Cookies are path-oriented. The default path attribute is , the WEB server page will automatically pass the current path to the browser. Specifying the path will force the server to use the set path.
Cookies set in one directory page cannot be seen in another directory page.

Five: Receiving and processing cookies
PHP’s processing of cookies is fully automatic, and the principle of processing FORM variables is the same. Of course, you can also use PHP global variables, the $HTTP_COOKIE_VARS array.
Example: echo $mycookie ;
echo $cookie Array[0];
echo count($cookie Array);
echo $HTTP_COOKIE_VARS["mycookie"];

Six: Delete cookies
 (1 ) Call setcookie() with only the name parameter;
(2) Make the expiration time time() or time-1;

7: Restrictions on using cookies
(1) Must be in The content of the HTML file is set before output;
(2) Different browsers handle cookies inconsistently, so you must consider them when using them;
(3) Client restrictions, such as user settings prohibiting cookies, the cookie cannot be created ;

Eight: A specific example, I hope everyone will have a deeper understanding of cookies
🎜>                                                                                                                                }
                                                                                                                                                                ;/Body & gt;
& lt;/html & gt;

How about, do you have a detailed understanding of the cookie function in PHP through the above introduction. Give it to your wisdom, let you make you your ingenuity, let you make you Let’s make the site more powerful. If you have any questions, please contact fbigov@sina.com. Let’s make progress together.



http://www.bkjia.com/PHPjc/315272.html

www.bkjia.com

true

TechArticleDetailed explanation of COOKIE support for PHP4 When establishing a commercial site or a personal site with relatively complete functions, it is often necessary to record visitor information. Two convenient methods are provided in PHP: session and cook...
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)

How to enable nfc function on Xiaomi Mi 14 Pro? How to enable nfc function on Xiaomi Mi 14 Pro? Mar 19, 2024 pm 02:28 PM

Nowadays, the performance and functions of mobile phones are becoming more and more powerful. Almost all mobile phones are equipped with convenient NFC functions to facilitate users for mobile payment and identity authentication. However, some Xiaomi 14Pro users may not know how to enable the NFC function. Next, let me introduce it to you in detail. How to enable nfc function on Xiaomi 14Pro? Step 1: Open the settings menu of your phone. Step 2: Find and click the "Connect and Share" or "Wireless & Networks" option. Step 3: In the Connection & Sharing or Wireless & Networks menu, find and click "NFC & Payments". Step 4: Find and click "NFC Switch". Normally, the default is off. Step 5: On the NFC switch page, click the switch button to switch it to on.

The difference between vivox100s and x100: performance comparison and function analysis The difference between vivox100s and x100: performance comparison and function analysis Mar 23, 2024 pm 10:27 PM

Both vivox100s and x100 mobile phones are representative models in vivo's mobile phone product line. They respectively represent vivo's high-end technology level in different time periods. Therefore, the two mobile phones have certain differences in design, performance and functions. This article will conduct a detailed comparison between these two mobile phones in terms of performance comparison and function analysis to help consumers better choose the mobile phone that suits them. First, let’s look at the performance comparison between vivox100s and x100. vivox100s is equipped with the latest

How to add trusted sites in Google Chrome How to add trusted sites in Google Chrome Jul 19, 2024 pm 04:14 PM

How to add trusted sites in Google Chrome? Some users cannot browse the web normally because the page prompts that it is not secure when surfing the Internet. At this time, they can add the website as a trusted site, and we can access it normally and surf the Internet smoothly. The editor below will bring you the steps to add a trusted site in Google Chrome. The steps are simple and easy to operate, and even beginners can easily get started. Friends who need it can learn about it together. How to add a trusted site in Google Chrome: 1. Open Google Chrome and click the three dots in the upper right corner. Click [Settings]. Choose privacy settings and security. (As shown in the picture) 2. Click Website Settings at the bottom of the page. (As shown in the picture) 3. Click on the unsafe content at the bottom of the page. (As shown in the picture) 4. Click the Add button to the right of the Allow option. (As shown in the picture) 5. Lose

What exactly is self-media? What are its main features and functions? What exactly is self-media? What are its main features and functions? Mar 21, 2024 pm 08:21 PM

With the rapid development of the Internet, the concept of self-media has become deeply rooted in people's hearts. So, what exactly is self-media? What are its main features and functions? Next, we will explore these issues one by one. 1. What exactly is self-media? We-media, as the name suggests, means you are the media. It refers to an information carrier through which individuals or teams can independently create, edit, publish and disseminate content through the Internet platform. Different from traditional media, such as newspapers, television, radio, etc., self-media is more interactive and personalized, allowing everyone to become a producer and disseminator of information. 2. What are the main features and functions of self-media? 1. Low threshold: The rise of self-media has lowered the threshold for entering the media industry. Cumbersome equipment and professional teams are no longer needed.

How to set line spacing in WPS Word to make the document neater How to set line spacing in WPS Word to make the document neater Mar 20, 2024 pm 04:30 PM

WPS is our commonly used office software. When editing long articles, the fonts are often too small to be seen clearly, so the fonts and the entire document are adjusted. For example: adjusting the line spacing of the document will make the entire document very clear. I suggest that all friends learn this operation step. I will share it with you today. The specific operation steps are as follows, come and take a look! Open the WPS text file you want to adjust, find the paragraph setting toolbar in the [Start] menu, and you will see the small line spacing setting icon (shown as a red circle in the picture). 2. Click the small inverted triangle in the lower right corner of the line spacing setting, and the corresponding line spacing value will appear. You can choose 1 to 3 times the line spacing (as shown by the arrow in the figure). 3. Or right-click the paragraph and it will appear.

What are the functions of Xiaohongshu account management software? How to operate a Xiaohongshu account? What are the functions of Xiaohongshu account management software? How to operate a Xiaohongshu account? Mar 21, 2024 pm 04:16 PM

As Xiaohongshu becomes popular among young people, more and more people are beginning to use this platform to share various aspects of their experiences and life insights. How to effectively manage multiple Xiaohongshu accounts has become a key issue. In this article, we will discuss some of the features of Xiaohongshu account management software and explore how to better manage your Xiaohongshu account. As social media grows, many people find themselves needing to manage multiple social accounts. This is also a challenge for Xiaohongshu users. Some Xiaohongshu account management software can help users manage multiple accounts more easily, including automatic content publishing, scheduled publishing, data analysis and other functions. Through these tools, users can manage their accounts more efficiently and increase their account exposure and attention. In addition, Xiaohongshu account management software has

The difference and comparative analysis between C language and PHP The difference and comparative analysis between C language and PHP Mar 20, 2024 am 08:54 AM

Differences and comparative analysis between C language and PHP C language and PHP are both common programming languages, but they have obvious differences in many aspects. This article will conduct a comparative analysis of C language and PHP and illustrate the differences between them through specific code examples. 1. Syntax and usage: C language: C language is a process-oriented programming language, mainly used for system-level programming and embedded development. The syntax of C language is relatively simple and low-level, can directly operate memory, and is efficient and flexible. C language emphasizes the programmer's completeness of the program

Detailed explanation of the role and usage of PHP modulo operator Detailed explanation of the role and usage of PHP modulo operator Mar 19, 2024 pm 04:33 PM

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

See all articles