downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

$php_errormsg> <$_ENV
Last updated: Fri, 06 Nov 2009

view this page in

$_COOKIE

$HTTP_COOKIE_VARS [非推奨]

$_COOKIE -- $HTTP_COOKIE_VARS [非推奨]HTTP クッキー

説明

現在のスクリプトに HTTP クッキーから渡された変数の連想配列です。

$HTTP_COOKIE_VARS は同じ情報を持っていますが、 これはスーパーグローバルではありません ($HTTP_COOKIE_VARS$_COOKIE は違う変数であり、PHP はそれぞれ別に扱います)。

変更履歴

バージョン 説明
4.1.0 $_COOKIE が導入され、 $HTTP_COOKIE_VARS は非推奨となりました。

例1 $_COOKIE の例

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

"name" というクッキーが事前に設定されているものとします。

上の例の出力は、 たとえば以下のようになります。

Hello Hannes!

注意

注意: これは 'スーパーグローバル' あるいは自動グローバル変数と呼ばれるものです。 スクリプト全体を通してすべてのスコープで使用することができます。 関数やメソッドの内部で使用する場合にも global $variable; とする必要はありません。



add a note add a note User Contributed Notes
$_COOKIE
Chris Watson
30-Sep-2009 12:18
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.
Sam Yong - hellclanner at live dot com
05-Sep-2009 02:27
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

?>

$php_errormsg> <$_ENV
Last updated: Fri, 06 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites