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!
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.