note 16974 added to language.variables.predefined

From: Date: Tue, 20 Nov 2001 20:46:11 +0000
Subject: note 16974 added to language.variables.predefined
Groups: php.notes 
Request: Send a blank email to php-notes+get-21078@lists.php.net to get a copy of this message
Using the register_globals function of PHP can be dangerous, but it is handy in some situations. You can however use this function (maybe with a little more functionality, this was all I needed) to make sure hacking doesn't occur, but you can use 1 line in your code to get either an environment, post, get or cookie variable. <? /* This function is safe, since it FIRST returns * any environment variables, making sure they * can't be overwritten! * Cookies are done last, since they are more * to hacking. */ function get_var($var) { global $HTTP_ENV_VARS; global $HTTP_POST_VARS; global $HTTP_GET_VARS; global $HTTP_COOKIE_VARS; if(trim($HTTP_ENV_VARS["$var"]) != "") return $HTTP_ENV_VARS["$var"]; if(trim($HTTP_POST_VARS["$var"]) != "") return $HTTP_POST_VARS["$var"]; if(trim($HTTP_GET_VARS["$var"]) != "") return $HTTP_GET_VARS["$var"]; if(trim($HTTP_COOKIE_VARS["$var"]) != "") return $HTTP_COOKIE_VARS["$var"]; } ?> Hope you find this useful, Jesse Meijers -- http://www.php.net/manual/en/language.variables.predefined.php http://master.php.net/manage/user-notes.php?action=edit+16974 http://master.php.net/manage/user-notes.php?action=delete+16974 http://master.php.net/manage/user-notes.php?action=reject+16974

« previous php.notes (#21078) next »