What is the method to get cookie value in php

青灯夜游
Release: 2023-03-11 10:54:02
Original
9327 people have browsed it

In php, you can use the super global variable "$_COOKIE" to obtain the browser's Cookie value; "$_COOKIE" is an array that stores all Cookie information, and you can use "$_COOKIE['Cookie name" ']" form to obtain the value of a specific cookie.

What is the method to get cookie value in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

What is Cookie

Cookie is to save the specific information of the browser browsing the web page in the form of a file on the client's hard drive. When you visit the website again, the browser will first try to read the cookie file, and the read data will be used by the browser. A common application is to log in to some web pages like spaces and blogs. These web pages usually have personalized settings for everyone, and they can be quickly displayed through cookie technology.

Cookies are commonly used in the following three aspects:

  • Record certain information about visitors. Just like the access space or blog mentioned earlier;

  • transfers data between pages. Usually cookies are not used to save data such as passwords, but when the data on one page is to be used on another page, it needs to be implemented through Cookie technology;

  • will be viewed Web pages are stored in cookie temporary files, which can speed up access to the web page.

Generally it is not recommended to use cookies to save data sets or other large data. At the same time, not all browsers support cookies, and the data information is saved on the client in the form of plain text. computer, so it is best not to save sensitive, unencrypted data, otherwise it will affect the security of the website.

php Get cookie value

In PHP, you can use the super global variable $_COOKIE to read the browser's Cookie value. $_COOKIE is an array that stores all cookie information. The value of a specific cookie can be obtained in the form of $_COOKIE['Cookie Name'].

Example: Use the superglobal variable $_COOKIE to get the value of Cookie.

<?php
    echo &#39;Website 的值为:&#39;.$_COOKIE[&#39;Website&#39;].&#39;<br>&#39;;
    echo &#39;Url 的值为:&#39;.$_COOKIE[&#39;Url&#39;].&#39;<br>&#39;;
    echo &#39;Title 的值为:&#39;.$_COOKIE[&#39;Title&#39;];
?>
Copy after login

The running results are as follows:

Website 的值为:php中文网
Url 的值为://m.sbmmt.com/
Title 的值为:Cookie
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the method to get cookie value in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template