note 55649 added to language.variables.variable

From: Date: Tue, 09 Aug 2005 17:23:24 +0000
Subject: note 55649 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-93326@lists.php.net to get a copy of this message
Note for "James" from the last entry: Don't you know that that is why REGISTER_GLOBALS was turned off by default, in the first place? You have to be very careful when dealing with user input, especially GET and POST; because having variables automatically assigned to the names of those values is dangerous, and can lead to someone manipulating the values of _other_ variables within the script, if they are of the same name. In any case, you could shorten those loops quite a bit by using foreach (although I would take heed of the above warning; or save myself any work at all and just turn the pre-existing feature on again, if I was working on a LAN or something, that I knew was 'safe'): <?php foreach($_GET as $k=>$v) { $$k = $v; } ?> Maybe you didn't know that REGISTER_GLOBALS did the same thing before? It's recommended that you leave it set as false, though, as I said, in all newer PHP versions. You're advised to just stick with the 'superglobals' -- if you just wanted to shorten the typing and be (very) lazy when it comes to not having to repeat $_GET or $_POST, lol, you could just assign, for example, $_G and $_P as aliases to the arrays (or references, if you want to save on the extra memory space that would be allotted if they were duplicates, i.e. $_G =& $_GET). ---- Manual Page -- http://www.php.net/manual/en/language.variables.variable.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55649 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55649&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55649&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55649&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55649&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55649&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55649&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55649&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93326) next »