Page 1 of 1

Which is better

Posted: Thu Jun 12, 2003 12:39 pm
by oldtimer
Okay you have several methods I see.

Post, Get and request are the most often seen.

Is it better to use
$HTTP_POST_VARS['whatever'];
or
$_POST['whatever'];

I have been using the first but there is less typing for the 2nd :lol:

Or is even better to use
$_REQUEST['whatever']))

Posted: Thu Jun 12, 2003 12:55 pm
by cactus
It's not a matter of which is best, it a matter of which is supported.

As of version 4.1 (I believe), the introduction of the new (2nd one) style evnironment variables supercedes the old style (1st one).

At present $HTTP_POST/GET_VARS['whatever'] are deprecated but still available (for backwards compatibility), this may not (most likely definitely not) be available in future releases.

Code being developed today should not use the old style vars as your software won't be future proof.

viewtopic.php?t=511

Regards,

Posted: Thu Jun 12, 2003 12:56 pm
by oldtimer
So then $_POST or $_REQUEST should be used.

On another note. do I have to use caps in it? Or can i hae $_post ?

Posted: Thu Jun 12, 2003 1:08 pm
by cactus
Nope, they are predefined:

http://www.php.net/manual/en/language.v ... efined.php

You could do:

Code: Select all

$_post = array();
$_post = $_POST;
Regards,

Posted: Thu Jun 12, 2003 3:21 pm
by twigletmac
But you'll probably find your code easier to maintain if you use the caps version especially since you'll then have the superglobal functionality as well.

Whether you use $_POST or $_REQUEST will depend - if you want to be sure that the data has been posted from a form use $_POST, if the data could come from either the URL, a posted form or a cookie use $_REQUEST. Being explicit as to where you are getting the information from can make it easier, once again, to maintain your code.

Mac