PHP 7.0.26 Released

$_COOKIE

$HTTP_COOKIE_VARS [obsoleta]

(PHP 4 >= 4.1.0, PHP 5, PHP 7)

$_COOKIE -- $HTTP_COOKIE_VARS [obsoleta]HTTP Cookies

Descrição

Um array associativo de variáveis passadas para o atual script via HTTP Cookies.

$HTTP_COOKIE_VARS contém o mesma informação inicial, mas não é uma superglobal. (Note que $HTTP_COOKIE_VARS e $_COOKIE são variáveis diferentes e que o PHP manuseia-as diferentemente)

Changelog

Versão Descrição
4.1.0 Introduzida a $_COOKIE que torna obsoleta a $HTTP_COOKIE_VARS.

Exemplos

Exemplo #1 Exemplo da $_COOKIE

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

Assumindo que o "nome" do cookie tenha sido definido antes

O exemplo acima irá imprimir algo similar à:

Hello Hannes!

Notas

Nota:

Esta é uma 'superglobal', ou global automática, variável. Isto simplismente significa que ela está disponível em todos escopos pelo script. Não há necessidade de fazer global $variable; para acessá-la dentro de uma função ou método.

add a note add a note

User Contributed Notes 4 notes

up
55
kiril (at) atern (dot) us
1 year ago
To clarify the previously posted note:

Dots (.) and spaces ( ) in cookie names are being replaced with underscores (_).
up
74
k dot andris at gmail dot com
2 years ago
beware, dots (.) in cookie names are replaces by underscores (_)
up
-148
Anonymous
5 months ago
spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam ?spam spam spam ?spam spam spam ?spam spam spam ?spam spam spam !
up
-153
Anonymous
5 months ago
spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam spam ?spam spam spam ?spam spam spam ?spam spam spam ?spam spam spam !
To Top