略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: $_COOKIE

2024-12-23

$_COOKIE

$_COOKIEHTTP Cookies

说明

通过 HTTP Cookies 方式传递给当前脚本的变量的数组

范例

示例 #1 $_COOKIE 范例

<?php
echo 'Hello ' htmlspecialchars($_COOKIE["name"]) . '!';
?>

假设之前发送了 "name" Cookie

以上例程的输出类似于:

Hello Hannes!

注释

注意:

“Superglobal”也称为自动化的全局变量。这就表示其在脚本的所有作用域中都是可用的。不需要在函数或方法中用 global $variable; 来访问它。

add a noteadd a note

User Contributed Notes 4 notes

up
61
kiril (at) atern (dot) us
6 years ago
To clarify the previously posted note:

Dots (.) and spaces ( ) in cookie names are being replaced with underscores (_).
up
61
k dot andris at gmail dot com
7 years ago
beware, dots (.) in cookie names are replaces by underscores (_)
up
-1
axodjakov at gmail dot com
11 months ago
$_COOKIE returns an array if there are more than one cookie saved under the given key.
up
-20
alexander-schranz at NO_SPAM dot hotmail dot com
4 years ago
Cookies with the same name the first cookie is used. Clients will send cookies with longer path before cookies with shorter path. This comes from RFC 6265 which says "Cookies with longer paths are listed before cookies with shorter paths.". So you get the best matching cookie for your current request.

官方地址:https://www.php.net/manual/en/reserved.variables.cookies.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3