Register global is default off after version 4.2.0. It's rare there are scripts that need register global support. But if there is one, here is a way can always extract register globals.
1. The very popular and common method:
foreach($_REQUEST as $key => $var){ $$key = $var; }
2. The import_request_variables() function:
This function globalize each value in $_GET, $_POST and $_COOKIE. It was introduced after PHP 4.1.0. The function takes 2 arguments: the first is which array will be extracted, 'G' for $_GET, 'P' for $_POST and 'C' for $_COOKIE(capitalization doesn't matter here). You can combine any of these three and only extract the ones you need. The second argument choses the prefix of each variable. prefix + the key in the array will be the new variable's name.
//suppose in $_POST['aa'] = 30; //$_POST['bb'] = 20; import_request_variables ('GPC','vars_'); echo $vars_aa;//30 echo $vars_bb;//20
Note: The extract() can be pretty useful here too.
Comments
nise job
nise job
Post new comment