doufu5521 2011-12-21 07:41
浏览 95
已采纳

这些东西在php中是什么? 例如:$ _COOKIE [],$ _POST []等

I'm just starting out, so please forgive if this is a silly question.

I'm learning by reading a book and watching a video series that may be slightly out-dated.

The instructions given in certain cases where more than one page is involved use regular variable syntax, but that syntax does not work unless I use the syntax mentioned in the title of this post.

Example from the video includes:

Page 1:

<?php

setcookie("color","blue");

?>

Page 2:

<?php

echo $color;

?>

This does not work for me. However, if I change things using the other syntax, it does work.

Example from changes to variable syntax that makes it work:

Page 1:

<?php

setcookie("color","blue");

?>

Page 2:

<?php

echo $_COOKIE["color"];

?>

So my question is, what is this syntax (ex: $_COOKIE["color"]) that I am using? What is it called and what/how does it work exactly?

I realize this has something to do with sessions, but am too novice to understand beyond that.

Thank you for your help!

展开全部

  • 写回答

4条回答 默认 最新

  • douxuanou2787 2011-12-21 07:44
    关注

    They are called Superglobals, they are "special" variables that are always defined.

    http://php.net/manual/en/language.variables.superglobals.php

    The first example can work if the evil, evil register_globals is enabled:

    http://php.net/manual/en/security.registerglobals.php

    If you are learning PHP from a source that is using register_globals, I suggest you find another source.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部