Why is _POST sometimes empty when a textarea is posted in PHP - php

PHP 4.4 and PHP 5.2.3 under Apache 2.2.4 on ubuntu.
I am running Moodle 1.5.3 and have recently had a problem when updating a course. The $_POST variable is empty but only if a lot of text was entered into the textarea on the form. If only a short text is entered it works fine.
I have increased the post_max_size from 8M to 200M and increased the memory_limit to 256M but this has not helped.
I have doubled the LimitRequestFieldSize and LimitRequestLine to 16380 and set LimitRequestBody to 0 with no improvement.
I have googled for an answer but have been unable to find one.
HTTP Headers on firefox shows the content size of 3816 with the correct data, so its just not getting to $_POST.
The system was running fine until a few weeks ago. The only change was to /etc/hosts to correct a HELO issue with the exim4 email server.
I can replicate the issue on a development machine that has exim4 not running so I think it is just coincidence.
Thanks for your assistance.

I don't know enough to really provide a useful answer so the following is more a well-educated guess (at least I hope so).
First, you should debug the entire request, either by access_log or for example through firebug. (Good to have Firebug anyway.) To me your problem sounds like a redirect happens in between. I give you an example:
Assume this is your structure:
/form.php
/directory/index.php
This is your form:
<form action="/directory" method="post">
...
</form>
Problem in this case is, that even though /directory is a valid url, Apache will redirect you one more time to /directory/, thus you are loosing your payload (what is supposed to be in $_POST).

Could it be not the size related of the post, but how long the line is before a new line. If they use the Moodle WYSIWYG view the html would just get put into one line with no breaks. If you go into html and hit return around every 1000 characters does it work?

What is the enctype of the form? Could be that it limits the ammount of data send through the form.
You might also want to check the incoming raw $_POST data with:
file_get_contents('php://input');
To make sure their is actually data send.
Got these suggestions here.

It sounds like an Apache or Apache/PHP integration problem. If $_POST is empty it would hint that the http server is not giving the POST information to PHP. If I were you I'd investigate the Apache configuration.

This is obvious, but did you /etc/init.d/apache2 restart ?
Also, the error_log file should show some information about whether the post size exceeded the set limit. Consider increasing your verbosity for troubleshooting the issue

Related

Ajax error - 0 after a long php script

I am using jquery ajax to send the url of a file (csv file) located on the server to my php script so as to process it.
The csv file contains telephone calls. If i have a file with even 10.000 calls everything is ok. But if i try a big file with like for example 20000 calls then i get an Ajax Error 0 . I check for server responce with firebug but i get none.
This behaviour occurs after like 40mins of w8ing for the php script to end. So why do i get this error on big files only? Does it have to do with apache, mysql or the server itself? Anyone able to help will be my personal hero cause this is driving me nuts.
I need a way to figure out whats happening exactly but firebug wont return a server responce. Any other way i can find out whats happening?
I checked the php error log and it reports nothing on the matter
Thanks in advance.
The script may have timed out:
See your php.ini file
max_execution_time
max_input_time ;# for the max time an input can be processed
Were your PHP.ini is depends on your enviroment, more information: http://php.net/manual/en/ini.php
Check:
max_input_time
This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. It is measured from the moment of receiving all data on the server to the start of script execution.
max_execution_time
This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.
Also
Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.
First enable php error by placing below code at top of the php file.
error_reporting(E_ALL);
Then as Shamil explained in this answer, checkout your max_execution_time settings of your php.
To check max_execution time, open your php.ini file and search for that, and then change it to a maximum value of say one hour (3600).
I hope this will fix your issue.
Thank you

Cannot send a string of more than 1333 characters

I have a strange problem. I cannot send a form if one the fields has a string of more than 1333 characters.
Here's my simple html page:
<form method="POST">
<input type="hidden" name="a" value="WffapzB...truncated" />
<input type="submit" value="OK" />
</form>
The problem comes from Apache or my Computer since when I load the html file in the browser (file://localhost/Users/etienne/Developpement/htdocs/test/SendForm/index.html), without passing through the server, the form gets sent.
If I access it via the server (http://tests.localhost/SendForm/), the page times out.
Here's what I have tried:
Also, all the php and apache logs do not show anything...
I've set post_max_size = 500M
I've set LimitBodyRequest 0
You can see my phpinfo page here: http://jsfiddle.net/etiennenoel/VZfeQ/
What can cause a page not to accept strings longer than 1333 characters on server side ? Clearly, it is not a browser problem since it doesn't work on other browsers and it works using the html file. Therefore, the problem comes when the server is in the process.
Update 2
I completely removed MAMP Server and reinstalled the Mac OS X native server without success. Therefore, it is not linked with MAMP PRO but with other things that I have not clue about...
Update 3
I also found out that the same problem occurs sending the data via GET.
Update 4
Using wireshark on my local adapter, I see no POST data being sent. I see the http requests for that page but it doesn't show any POST requests. If I launch another site, then I will see the POST requests for that site. : https://docs.google.com/file/d/0B2quoUxT9OnJdmN3ajJVR2dPbUk/edit?usp=sharing
I finally found it ! After hours and days of searching, I decided to reactivate the firewall. Then, I got a request from a program called HideMyIp (that I completely forgot that I had installed). I deleted that program, restarted my computer, and everything was then working fine ! Thanks to everyone that have tried to help me !

HTTP Post file to webserver failure

From our offline application we want to post an xml file via HTTP Post to our webserver. This worked fine but when the xml is larger then 650KB the post failed.
The PHP settings on our webserver:
memory_limit 128M
post_max_size 32M
upload_max_filesize 16M
Somebody knows what the problem could be?
UPDATE
I've tested something on our webserver. I made a form with a textarea and paste the XML in the textarea. When I submitted the form I didnt get any results of the POST I echoed but when I paste the half of the XML I get the results.
Strange thing is I didnt got an error message when posting the whole XML.
Try putting this at the top of php file that you call on form submit:
set_time_limit(0);
Maybe your connection is too slow to send that file in allowed execution time of php script.
Run phpinfo() and check if these variables are what you think are. Maybe some .htaccess or other webserver configuration file is overwriting them. Also check if there's no connection timeout.
What response do you get from server when post fails?

php loses form POST parameters

I have a form which sends data with the POST method, about 3000 array keys to be inserted in MySQL like this:
client_add[]=1
client_add[]=3
client_add[]=47
...
The problem is on my localhost on the development server works just fine. On production I only get about 1000 rows, on the localhot it seems to get lost, we confronted the php.ini files and the development server has everything set to more memory than my localhost.
I've run out of ideas.
The size of the post body will be somewhere around 50kb, which is ok as long as the server and/or PHP doesn't enforce a limit. It seems like your production environment enforces such a limit. You should check the entire webserver configuration, and if that is identical as well, compare compile-time defaults. Maybe the phpinfo() call shows more on the actual limits.
PHP has an ini setting which dictates the size of your POST request, you can probably find it in your ini under the name of post_max_size.
Also, if you've got the Suhosin patch installed it will enforce a limit on the number of POST variables you can submit on each request. I think this is around 2000 by default.

post variable problem

I'm working on a web site which creates images online ... there is an SWF which sends variables via post to PHP, and it works fine on my PC but when I test on the server, there are missing variables, specifically the one which contains the colour of the pixels in the image (biggest image is 77 kb). I have set up post_max_size = 32M
Any clue what the problem might be?
There might be some security enforced on PHP to block binary data in POST variables (Suhosin, mod_security, etc.).
Agreed with Michal. Sometimes when something works fine on localhost but not own other sever is also because of short tags. If you have enabled short tags on local server but not on other server, you are bound to receive error or un-expected output. So check with matching of short tags also.

Categories