dismiss Step into the future! Click here to switch to the beta php.net site
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

$php_errormsg> <$_ENV
[edit] Last updated: Fri, 28 Jun 2013

view this page in

$_COOKIE

$HTTP_COOKIE_VARS [obsoleta]

$_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 $_COOKIE - [2 notes]
up
3
Chris Watson
3 years ago
The value of $_COOKIE is determined by the content of cookies received in the user agent's request.

If you set a cookie (ie send it to the browser), it won't be sent back until the next request and so the data won't be present in $_COOKIE.
up
-1
Sam Yong - hellclanner at live dot com
3 years ago
Take note that in IE when it's really weird that when you do something like this:

<?php

// import config/constants

session_set_cookie_params((time()+$_SITE['session_length']));
session_start();
$sess = session_name();
setcookie($sess, $_COOKIE[$sess], time() + $_SITE['session_length']);

// .. rest of the code

?>

It fails. the session cookie is not stored totally.

Instead, doing this would work:

<?php

// import config/constants

session_set_cookie_params((time()+$_SITE['session_length']));
session_start();
$sess = session_name();
setcookie($sess, session_id(), time() + $_SITE['session_length']);

// .. rest of the code

?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites