1
phatjew
"$HTTP_POST_VARS as $k" -- what is this?
  • 2004/3/17 18:16

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


Quote:
if (isset($HTTP_GET_VARS)) {
foreach ($HTTP_GET_VARS as $k => $v) {
$$k = $v;
}
}
if (isset($HTTP_POST_VARS)) {
foreach ($HTTP_POST_VARS as $k => $v) {
$$k = $v;
}
}


Forgive my ignorance, but I am modifying (rewriting) a module that has this line at the top of the index.php (and several other places). What does it do? Can I remove it and use $_POST instead, or will that cause people problems who aren't using the latest versions of PHP?

2
pdaddict
Re: "$HTTP_POST_VARS as $k" -- what is this?
  • 2004/3/17 18:29

  • pdaddict

  • Friend of XOOPS

  • Posts: 106

  • Since: 2003/4/6 1


I saw this code on another forum too, and if I remember correctly, it is used to convert $_POST['postedvar'] to $postedvar, so it's actually being used to make the module work with register_globals off.

3
Mithrandir
Re: "$HTTP_POST_VARS as $k" -- what is this?

It does exactly that.

For each $HTTP_POST_VARS (which btw should be $_POST in the future) it takes the index and turns it into a variable - just like register globals.

The official XOOPS opinion is that we module developers shouldn't be so lazy and start using $_POST['varname'] instead of this loop to get $varname. This is a good coding practice and will hopefully make it easier to sustain security in XOOPS.

4
phatjew
Re: "$HTTP_POST_VARS as $k" -- what is this?
  • 2004/3/17 19:18

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


So, what I am hearing is that I can simply delete these lines, and anytime I need to access $_POST data, I should just use $_POST['thingy']. OK, I will take Mithrandir's advice and not be lazy.

On a related note, if I want to send all the POST data to a function, can I just do this:

$result = doYourThingWithPOSTData($_POST);

Does that make a copy, or can I send it by reference by defining my function like this (I am a C++ programmer in real life, so this syntax could be wrong):

function doYourThingWithPOSTData(&$_POST){ . . . }


Or, is there a better way to make all current $_POST data available inside other functions and classes other than explicitly passing it? Basically, I have code that works now, but I am refactoring to make it much simpler and object-oriented. Before, everything was in index.php, but that has grown too big to manage.

Thanks for any help.

5
Mithrandir
Re: "$HTTP_POST_VARS as $k" -- what is this?

I believe $_POST, $_GET, $_COOKIE, $_SERVER, $_SESSION etc. are all available in functions as well - even without defining them as global in the function declaration.

6
Dave_L
Re: "$HTTP_POST_VARS as $k" -- what is this?
  • 2004/3/17 21:14

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Yes, those variables are called superglobals, and are available everywhere, including functions.

Login

Who's Online

164 user(s) are online (85 user(s) are browsing Support Forums)


Members: 0


Guests: 164


more...

Donat-O-Meter

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

Latest GitHub Commits