1
snakes
Register Globals OFF - A suggestion on how to by pass
  • 2004/10/7 15:05

  • snakes

  • Just popping in

  • Posts: 69

  • Since: 2004/8/8 0


It is sometime tiring to use $HTTP_POST_VARS and $HTTP_GET_VARS to access variable passed by URLs of forms.

Few couple of minutes ago, I got an idee and wanted to discussed it.

The eval() function is used to evaluate a string as PHP commands. This mean you can create a string dynamically and evaluate it.

So you can recreate the function that Register Globals is calling when set to ON.

You can also add a prefix to each variable so you can tell which are POST and which are GET variables.

$post_prefix="p_";
$get_prefix="g_";
$cmd="";
while(list(
$key,$val)=each($HTTP_GET_VARS)) {
        
$cmd.="$".$get_prefix.$key."="".$val."";";
}
while(list(
$key,$val)=each($HTTP_POST_VARS)) {
        
$cmd.="$".$post_prefix.$key."="".$val."";";
}
eval(
$cmd);


$p_address could then be the Address field of a form sent by POST method.

$g_action could be the variable sent via the URL.

This can also be used to port some PHP script that do not require high security level. Setting
$post_prefix="";
$get_prefix="";

will avoid you to pass by $HTTP_POST_VARS or $HTTP_GET_VARS

2
ackbarr
Re: Register Globals OFF - A suggestion on how to by pass

I do something similar, but instead of taking the full $HTTP_POST_VARS and $HTTP_GET_VARS (which by the way are disabled by default in PHP 5, use $_POST and $_GET instead) I create an array of variables I am expecting and loop through that, so that only my desired values are retrieved. In addition if you find the typing to be tedious, you could always assign the POST and GET arrays to a shorter variable name:

$_p =& $HTTP_POST_VARS;
$_g =& $HTTP_GET_VARS;

3
snakes
Re: Register Globals OFF - A suggestion on how to by pass
  • 2004/10/7 15:30

  • snakes

  • Just popping in

  • Posts: 69

  • Since: 2004/8/8 0


Yeah that's right to.
But I'm so lazy that I find tedious to do things such as
$sql="select * from table where name='".$_p["name"]."' order by id;";

I would prefer
$sql="select * from table where name='$p_name' order by id;";


4
Dave_L
Re: Register Globals OFF - A suggestion on how to by pass
  • 2004/10/7 15:49

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


You can do this:

$sql="select * from table where name='{$_p["name"]}' order by id;";


However, a request variable should be sanitized before use in a query, so you probably wouldn't want to do it this way.

5
snakes
Re: Register Globals OFF - A suggestion on how to by pass
  • 2004/10/7 15:56

  • snakes

  • Just popping in

  • Posts: 69

  • Since: 2004/8/8 0


OH cool.
The sanitization can be done in a loop before a request.

Login

Who's Online

233 user(s) are online (168 user(s) are browsing Support Forums)


Members: 0


Guests: 233


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits