Viewed   74 times

I have a very big html form (containing table with rows, which contain multiple inputs), which i need to submit to PHP script via POST request. The problem is some values don't come through and are absent in PHP's $_POST superglobal.

I checked (using Firebug extension) that the values are actually sent to server by the browser.

$_POST gets populated, but some values are just missing.

I checked what is raw request using:

$raw_post = file_get_contents('php://input');

and the string returned has the values. They are just not parsed into $_POST array. The strange thing i noticed is, it seems that the php://input values are cut after some length, and rest of the string does not come through to $_POST.

I thought about post_max_size and memory_limit and set them to large values:

memory_limit = 256M
post_max_size = 150M
but according to php documentation $_POST should not contain any values if request made is bigger than post_max_size.

Due to big size of form and request I cannot post it here, but i can post php script i used to debug the problem:


var_dump($file = file_get_contents('php://input'));
var_dump($_POST);
//... then i parsed the $file

Server version: Apache/2.2.9 (Debian)
PHP version: PHP 5.3.2-0.dotdeb.2

Can enyone explain reason of such strange PHP behaviour, and what should i do (change php settings, code?) to use $_POST array while processing form?

EDIT: To be clear: not only the values are missing. $_POST does not contain these keys either.

e.x. fragment of raw post:

t_dodparam%5B198%5D=&t_dodparam2%5B198%5D=&t_kolejnosc%5B198%5D=199&n_indeks=201&n_wartosc=testtesttest

Key 't_dodparam' is in post and it has key 198. The rest of parameters are missing (e.x. t_dodparam2 is in post, but it has no such key as 198, and there is no such key as n_wartosc in $_POST)

 Answers

3

PHP modifies fields containing the characters space, dot, open square bracket and others to be compatible with with the deprecated register_globals

you can find a lot of workarounds in the comments here: PHP: Variables From External Sources

For Exampe (comment by POSTer):

<?php
//Function to fix up PHP's messing up POST input containing dots, etc.
function getRealPOST() {
    $pairs = explode("&", file_get_contents("php://input"));
    $vars = array();
    foreach ($pairs as $pair) {
        $nv = explode("=", $pair);
        $name = urldecode($nv[0]);
        $value = urldecode($nv[1]);
        $vars[$name] = $value;
    }
    return $vars;
}
?>
Sunday, August 7, 2022
5

you would need 2 forms on your page, one form that posts back to index.php and a second form that posts to paypal

after the first form posts back to index.php, echo javascript in the body tag to submit the paypal form when it loads

    <?php
   if(isset($_POST['mydatafield'])){

        do database stuff

        $LOAD = 'document.paypal.submit();';
    }
    ?>
    <body onload="<?php echo $LOAD ?>">
    <form name="paypal" action="paypal.com?yadayada">
    paypal fields
    </form>
    <form name="myform" action="index.php">
    your form stuff
    submit button
    </form>
Sunday, September 18, 2022
2

Your post data is JSON so use json_decode to turn it into an array containing anobject and access the object_id property

$rawPostData = file_get_contents('php://input');
$json = json_decode($rawPostData);
$json = $json[0];
$all = date("F j, Y, g:i a") . " " . $json->object_id. "rn";
file_put_contents("Activity.log", $all, FILE_APPEND);
Monday, October 3, 2022
 
pope
 
3

A concise way to do it with your two data structures would be:

count( array_intersect( str_split($my_string), $special_chars ) )

That would also tell you how many of the special characters are in the string.

You could otherwise write a loop for your character list and manually probe with strpos.

The least effort would be converting your special character list into a regex charclass and testing against the string.

Monday, August 29, 2022
1

$response contains two entries: statuses and search_metadata. You probably want to iterate through statuses, so you should loop like this:

foreach($response['statuses'] as $tweet)
{
    $text = $tweet['text'];
}

The next problem you will face with this code is $url and $hashtag - they are arrays so you can't just echo them, you have to iterate and gather only relevant info to echo.

And one more thing:

echo "<pre>". var_dump($response) ."</pre>";

var_dump does not return anything, so it can not be concatenated to <pre>. To have readable output, use it like this:

echo "<pre>";
echo var_dump($response);
echo "</pre>";
Friday, December 9, 2022
 
g._cito
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :