From $_GET to $_POST – PHP

  php

Q(Question):

I have an inherited class method that is required to *only* handle
items from $_POST (and $_POST alone, for security reasons), for
validation and action processing.

Problem is that there is a section in my application that has to put
everything into an encoded query string for HTML reasons (the page is
a giant form and if I were to put the stuff into individual forms, I
would have a bunch of embedded forms inside one form and that is an
HTML no-no). So I need to figure out how to put everything into
$_POST from $_GET before the validator handles it.

I’ve tried but when I do that, $_POST exists, but even with
register_globals turned on, while $_POST[‘section’] exists, $section
does not.

How do I put $_GET into $_POST and keep it there?

Thanx
Phil

A(Answer):

["Followup-To:" header set to comp.lang.php.]
Phil Powell wrote:

How do I put $_GET into $_POST and keep it there?

<?php
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {

/* put $_GET into $_POST */
$_POST[‘GET’] = $_GET;

echo ‘Hi ‘, $_POST[‘username’];
echo "<pre>\n\nPOST is "; print_r($_POST); exit(‘</pre>’);
}

echo <<<HTML
<form action="{$_SERVER[PHP_SELF]}?a=b&c=d" method="post">
<!– $_GET variables ^^^^^^^ –>

Name: <input type="text" name="username"/><input type="submit"/>
</form>
HTML;

?>


USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :

A(Answer):

Phil Powell <so*****@erols.com> wrote:

How do I put $_GET into $_POST and keep it there?

http://nl.php.net/array_merge

BTW an other solution in this special situation might be the $_REQUEST
array.

Daniel Tryba

A(Answer):

"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om…

How do I put $_GET into $_POST and keep it there?

$_POST = $_GET;

A(Answer):

Actually that is what I thought as well, however, the problem everyone
overlooked is that while $_POST "gets" $_GET, the HTTP header still
has $_POST as.. nothing.

So that means with register globals on your global variables parsed
from $_POST are still having to be parsed manually in spite of the
fact that you set $_POST as $_GET, so you have to do this:

$_POST = $_GET;
foreach ($_POST as $key => $val) if (!isset(${$key})) ${$key} = $val;

Phil

"Chung Leong" <ch***********@hotmail.com> wrote in message news:<Gf********************@comcast.com>…

"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om…

How do I put $_GET into $_POST and keep it there?

$_POST = $_GET;

A(Answer):

"Phil Powell" <so*****@erols.com> wrote in message
news:1c*************************@posting.google.co m…

Actually that is what I thought as well, however, the problem everyone
overlooked is that while $_POST "gets" $_GET, the HTTP header still
has $_POST as.. nothing.

So that means with register globals on your global variables parsed
from $_POST are still having to be parsed manually in spite of the
fact that you set $_POST as $_GET, so you have to do this:

$_POST = $_GET;
foreach ($_POST as $key => $val) if (!isset(${$key})) ${$key} = $val;

But if register_globals is on, then the values in $_GET would become globals
automatically. There’s also extract() if you want to mimick register_globals
behavior. No need to do things manually.

A(Answer):

"Chung Leong" <ch***********@hotmail.com> wrote in message news:<6O********************@comcast.com>…

"Phil Powell" <so*****@erols.com> wrote in message
news:1c*************************@posting.google.co m…

Actually that is what I thought as well, however, the problem everyone
overlooked is that while $_POST "gets" $_GET, the HTTP header still
has $_POST as.. nothing.

So that means with register globals on your global variables parsed
from $_POST are still having to be parsed manually in spite of the
fact that you set $_POST as $_GET, so you have to do this:

$_POST = $_GET;
foreach ($_POST as $key => $val) if (!isset(${$key})) ${$key} = $val;

Actually we’re planning to have it set up so that it behaves the same
across platforms as this will be a portable application I’m building.
So we have to be able to have it work whether register_globals is on
or off. We’ll be testing it by making sure it’s turned off on this
server first.

Thanx
Phil
But if register_globals is on, then the values in $_GET would become globals
automatically. There’s also extract() if you want to mimick register_globals
behavior. No need to do things manually.

LEAVE A COMMENT