Home >Backend Development >PHP Problem >What is the method to get cookie value in php
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.
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 'Website 的值为:'.$_COOKIE['Website'].'<br>'; echo 'Url 的值为:'.$_COOKIE['Url'].'<br>'; echo 'Title 的值为:'.$_COOKIE['Title']; ?>
The running results are as follows:
Website 的值为:php中文网 Url 的值为://m.sbmmt.com/ Title 的值为:Cookie
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!