Register globals inactive and you want it's function?

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

Anonymous's picture

nise job

nise job

Post new comment

  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <fn>
  • Lines and paragraphs break automatically.
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Mathematical equations and graphs can be added between [tex] and [/tex], [graph] and [/graph] tags.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

Honey Pot that kill bots