Just out of curiosity

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Just out of curiosity

Post by superdezign »

I'm almost done my first E-commerce website and I just got to thinking...

I've got into this habit, not sure if it's valid or not, of using $HTTP_POST_VARS instead of $_POST, but I still use $_GET.


Is there any difference between $HTTP_POST_VARS and $_POST in php?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

$HTTP_POST_VARS is depreciated, and I do believe that it has been turned off by default on php5, and will be removed as of php6
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And $HTTP_POST_VARS is a normal array in global space while $_POST is a so-called superglobal array.

Code: Select all

function foo() {
  global $HTTP_POST_VARS;
  echo count($HTTP_POST_VARS);
}

// but
function bar() {
  echo count($_POST);
}
Using $_GET but $HTTP_POST_VARS is inconsistent and on a code review I would even mark it as error.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Okay, thanks. The reason I started using it was because I got an error from $_POST, but I'm sure I meant to change it back to $_POST after getting the same error with $HTTP_POST_VARS

Thanks for the enlightenment.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And what error do you get?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Hmm? Oh I'm not getting any errors. I just had a feeling that I shouldn't be using $HTTP_POST_VARS. I guess I was right.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

error
superdezign wrote:because I got an error from $_POST, but I'm sure I meant to change it back to $_POST after getting the same error with $HTTP_POST_VARS
or no error
superdezign wrote:Oh I'm not getting any errors.
that is the question...
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

try adding the @ before the $_POST[''] like this

Code: Select all

@$_POST['string']
or at least check to see if is set like this:

Code: Select all

if(isset($_POST['string'])){
...
}
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

louie35 wrote:try adding the @ before the $_POST[''] like this

Code: Select all

@$_POST['string']
Never, ever, ever do that. Fix the problem, don't just hide it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

onion2k wrote:Never, ever, ever do that. Fix the problem, don't just hide it.
Indeed.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

volka wrote:error
superdezign wrote:because I got an error from $_POST, but I'm sure I meant to change it back to $_POST after getting the same error with $HTTP_POST_VARS
or no error
superdezign wrote:Oh I'm not getting any errors.
that is the question...
No no.. nobody is understanding me 8O

I mean once, a long time ago, I had an error and was using $_POST, and tried using $HTTP_POST_VARS after looking at something I googled, but I also changed the surrounding code

Just somehow, something in my mind made me think the error had something to do with the fact that I used $_POST, but I just looked at it again and the problem was earlier on in the code. It's been fixed though.


This topic was just a question as to the difference between the two.
No errors. Sorry if I confused anyone :-p
Post Reply