You are here: Re: Variable passed in GET or POST array « PHP Programming Language « IT news, forums, messages
Re: Variable passed in GET or POST array

Posted by Pedro Graca on 01/19/06 12:17

Chuck Anderson wrote:
> I have finally started coding with register_globals off (crowd roars -
> yeay!).

YEAY!

> This has created a situation that I am not sure how I should handle. I
> have scripts (pages) that can receive an input variable from the POST
> array (initial entry) or it could be in the GET array (go back and
> re-edit a form, for instance.)

Why is it not POST again?

> In my old sloppy scripting days this was no problem, as I had
> register_globals on and would merely access the the input variable by
> it's local name (whether it was POST or GET made no difference).
>
> What's the best way to handle this situation where I am not sure if the
> input variable is in the GET array or the POST array? My guess is to
> test for the presence of the variable (isset, != '') in either array and
> then copy it to a local variable from that array.

Just know what you want and use it;
if you want something in the POSTed data, use $_POST
if you want something passed in the URL, use $_GET

> Is that the best, only, or most efficient way to handle that?

As Kimmo said you can use the $_REQUEST array which is contains
(almost (*)) all the $_GETs and $_POSTs.

(*) The $_REQUEST array will *not* have duplicate keys from $_GET,
$_POST, and $_COOKIE. There's a configuration value that specifies what
order is followed when PHP builds the $_REQUEST array (default is GPC,
meaning GET, POST, COOKIE).

If you have
$_GET['id'] = 4;
$_POST['id'] = 14;
$_COOKIE['id'] = 77;

$_REQUEST['id'] will be 77.

I never needed to use $_REQUEST and I always know whether the user input
comes from $_GET, $_POST, or $_COOKIE.

--
If you're posting through Google read <http://cfaj.freeshell.org/google>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация