Are quotes really required in $_SERVER ?
Posted: Fri Jul 11, 2008 5:13 am
PHP manual lists the usage of PHP_SELF in $_SERVER with single quotes.. ie.
But when I use it in the following way:
I get the following error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/.../index.php on line 19 (which is the above line)
And removing the quote works fine. Escaping the quotes with '\' also doesnt work.
As a side note, the following usage also seems to work (and so does the one with quotes around PHP_SELF)....
So, my question is:
Are quotes really required when using $_SERVER?
How about in the case of other reserved variables?
Code: Select all
$_SERVER['PHP_SELF']Code: Select all
header("Location: $_SERVER['PHP_SELF']") ; Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/.../index.php on line 19 (which is the above line)
And removing the quote works fine. Escaping the quotes with '\' also doesnt work.
As a side note, the following usage also seems to work (and so does the one with quotes around PHP_SELF)....
Code: Select all
<form action="<?php echo $_SERVER[PHP_SELF]; ?>?p=login" method="post"> Are quotes really required when using $_SERVER?
How about in the case of other reserved variables?