note 34484 added to function.import-request-variables
| From: | phackwer at hotmail dot com | Date: | Mon, 28 Jul 2003 22:30:38 +0000 |
| Subject: | note 34484 added to function.import-request-variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52869@lists.php.net to get a copy of this message | ||
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("'","'",$$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("'","'",$$session_var_name);
}
}
}
----
Manual Page -- http://www.php.net/manual/en/function.import-request-variables.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34484
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34484&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34484&report=yes