httpget $user_id;
httppost $credit_card;
session $really_important_stuff;
Each of these declaration lines would effectively enable
register_globals for one specific variable in one particular method
(GET, POST or session).
Creative suggestions, comments would be welcome.
Justin Koivisto wrote: The proposal in the form of functions:
<?php
// usage example
global_session('var1');
function global_get($var){
if(!array_key_exists($var,$_GET))
$_GET[$var]='';
$GLOBALS[$var]=&$_GET[$var];
}
function global_post($var){
if(!array_key_exists($var,$_POST))
$_POST[$var]='';
$GLOBALS[$var]=&$_POST[$var];
}
function global_session($var){
if(!array_key_exists($var,$_SESSION))
$_SESSION[$var]='';
$GLOBALS[$var]=&$_SESSION[$var];
}
function global_cookie($var){
if(!array_key_exists($var,$_COOKIE))
$_COOKIE[$var]='';
$GLOBALS[$var]=&$_COOKIE[$var];
}
function global_server($var){
if(!array_key_exists($var,$_SERVER))
$_SERVER[$var]='';
$GLOBALS[$var]=&$_SERVER[$var];
}
function global_files($var){
if(!array_key_exists($var,$_FILES))
$_FILES[$var]='';
$GLOBALS[$var]=&$_FILES[$var];
}
function global_env($var){
if(!array_key_exists($var,$_ENV))
$_ENV[$var]='';
$GLOBALS[$var]=&$_ENV[$var];
}
function global_request($var){
if(!array_key_exists($var,$_REQUEST))
$_REQUEST[$var]='';
$GLOBALS[$var]=&$_REQUEST[$var];
}
?>The proposal makes it explicit which variables you expect to use from
the _GET array, so an unexpected variable won't get extracted and
overwrite the session variable you intended to use. You get nearly
the convenience of register_globals=on with none of the security
risk.
I broadened the scope of the proposal in the process. These functions
now support all of the super globals (except$ GLOBALS)in PHP. I also
changed the names to be prefixed by global_ and then the lowercase
name of the superglobal array to play with.
Also, I thought about the case where the key didn't exist in the
superglobal. If this is the case, the key is created and then
referenced. This would likely be handy for _SESSION more than
anything.
Just wanted to follow-up on this one. Did this actually satisfy the
proposal set forth by the OP? I haven't noticed any posts to the thread
since I submitted this.
Ideas/comments/suggestions welcome on this as well.
--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.