doufu5521 2011-12-21 15: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 15: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条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助