note 34484 rejected from function.import-request-variables by torben

From: Date: Mon, 28 Jul 2003 23:40:13 +0000
Subject: note 34484 rejected from function.import-request-variables by torben
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-52873@lists.php.net to get a copy of this message
Note Submitter: phackwer@hotmail.com ---- A workaround for the disabled register globals. People around the work (I like the word around... :-), Here's a function I made that will register all variables again in the global scope. What for? Well, suppose you have always worked with the god damn register_globals option sets to on and you have to delivery a system tomorrow to your customer. Then, you discover that the big great son of a b... has a server with this god damn option off and the god damn sysadmin don't want to turn it on because he read somewhere that it's not safe, plus he don't trust your code 'cause he didn't do it, althought everyone else thinks you're the guy for the job and all that. Ok, enought with the history. Here's the function you need to help you not having to rewrite all your code. All you have to do is execute it once at the top of your code. First thing. I take no responsabilitie if this explodes your code, turn off your monitor, crashs your hard disk or anything. Use at your own. Have fun! pH4c|<VV3r function import_and_filter_all_variables_to_global_scope() { if ($_SERVER) { $server_var_names = array_keys($_SERVER); for ($j = 0; $j < count($_SERVER); $j++) { $server_var_name = $server_var_names[$j]; global $$server_var_name; $$server_var_name = $_SERVER[$server_var_name]; } } if ($_REQUEST) { $request_var_names = array_keys($_REQUEST); for ($j = 0; $j < count($_REQUEST); $j++) { $request_var_name = $request_var_names[$j]; global $$request_var_name; $$request_var_name = $_REQUEST[$request_var_name]; if (!is_array($$request_var_name)) { $$request_var_name = htmlspecialchars($$request_var_name); $$request_var_name = str_replace("'","&#39;",$$request_var_name); } } } if (count($_SESSION)) { $session_var_names = array_keys($_SESSION); for ($j = 0; $j < count($_SESSION); $j++) { $session_var_name = $session_var_names[$j]; global $$session_var_name; $$session_var_name = htmlspecialchars($_SESSION[$session_var_name]); $$session_var_name = str_replace("'","&#39;",$$session_var_name); } } }

« previous php.notes (#52873) next »