note 29266 modified in language.variables.variable by jsheets
| From: | jsheets@php.net | Date: | Sat, 08 Feb 2003 00:27:09 +0000 |
| Subject: | note 29266 modified in language.variables.variable by jsheets | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43592@lists.php.net to get a copy of this message | ||
[Editor's Note]
If you truly want to extract the variables from super globals instead of looping over the array use
extract(); or turn register globals on via an .htaccess file so it is enabled only for the script(s)
that depend on it.
[End Note]
A lot of the php code out there relies on register_globals being set to "on" in the
php.ini -- which may not be an option for some developers. It seems that the following function
would attempt to overcome that issue for later versions of php. I haven't tried it out yet, as
I have no need for it right now -- and it may pose some of the same issues as if you had
register_globals set to "on" -- but here it is, anyway.
function getRequestVariables()
{
foreach ($_POST as $postKey => $postValue)
{
global $$postKey;
$$postKey = trim (stripslashes ($postValue));
}
foreach ($_GET as $getKey => $getValue)
{
global $$getKey;
if (empty($$getKey))
{
$$getKey = trim (stripslashes ($getValue));
}
}
}
--was--
A lot of the php code out there relies on register_globals being set to "on" in the
php.ini -- which may not be an option for some developers. It seems that the following function
would attempt to overcome that issue for later versions of php. I haven't tried it out yet, as
I have no need for it right now -- and it may pose some of the same issues as if you had
register_globals set to "on" -- but here it is, anyway.
function getRequestVariables()
{
foreach ($_POST as $postKey => $postValue)
{
global $$postKey;
$$postKey = trim (stripslashes ($postValue));
}
foreach ($_GET as $getKey => $getValue)
{
global $$getKey;
if (empty($$getKey))
{
$$getKey = trim (stripslashes ($getValue));
}
}
}
http://www.php.net/manual/en/language.variables.variable.php