I'm working with a web store package which gives me specific places
where I can insert my code. I am trying to modify $_POST variables
after a form is submitted, and before the store actually processes
them. This is within a class function. Problem is, any $_POST variable
I modify is disappearing from the end result. I don't know if there's
a warning being thrown that the web store is suppressing or what, but
it's my modification of the values that seems to be screwing things
up. I came across a post in the PHP documentation that mentioned
something about superglobals not being able to be modified in
variables, but gave no solution. Does anybody know what the deal is,
and how I might be able to modify my $_POST variables?
Thanks,
Kevin
Hi Kevin,
You can modify the $_POST array just as you like.
You must make a mistake elsewhere.
Here is an example that shows that:
----------------------------------------
Post before:
<br>
<pre>
<?php print_r($_POST); ?>
</pre>
<?php
$_POST["test"] = "bla";
?>
<hr>
after:
<br>
<pre>
<?php print_r($_POST); ?>
</pre>
----------------------------------------
How are you reposting the data? Via Curl?
Regards,
Erwin Moller
It's a little bit different. I'm trying to modify the $_POST variables
inside a function. When I modify $_POST inline like you show, it works
just fine. It's when it's within a function that the outcome is
screwy. My example would look like this:
<?php
function modifyPost() {
$_POST['var1'] = 'foo';
}
?>
Post before:
<br>
<pre>
<?php print_r($_POST); ?> //Prints [var1] = foo
</pre>
<?php
modifyPost();
?>
<hr>
after:
<br>
<pre>
<?php print_r($_POST); ?> // Prints [var1] = ''
</pre>
Hi Kevin,
>
> It's a little bit different. I'm trying to modify the $_POST variables
> inside a function.
Doesn't matter. $_POST is a superglobal.
When I modify $_POST inline like you show, it works
> just fine. It's when it's within a function that the outcome is
> screwy.
It shouldn't be.
My example would look like this:
>
> <?php
>
> function modifyPost() {
> $_POST['var1'] = 'foo';
> }
> ?>
>
> Post before:
> <br>
> <pre>
> <?php print_r($_POST); ?> //Prints [var1] = foo
No, it does NOT.
POST should be empty there, no var1 is set yet.
[See my output below]
> </pre>
>
> <?php
> modifyPost();
> ?>
> <hr>
> after:
> <br>
> <pre>
> <?php print_r($_POST); ?> // Prints [var1] = ''
No it doesn't over here. [See my output below]
> </pre>
Your example outputs the following on my PHP5 machine:
Post before:
Array
(
)
after:
Array
(
[var1] => foo
)
Which is excactly what one expects when it comes to superglobals like
$_POST[].
Superglobal means you can access it anywhere from your code without
paying attention to scope, eg in a function.
Did you TRY your own code you posted anyway?
You must be doing something else (wrong) than this.....
Please test your own example above and tell us what the output is.
Regards,
Erwin Moller