Mysterious text truncation error/bug in PHP results in ...cut - php

I am experiencing a maddening issue with PHP that I can't seem to resolve. In some cases when a form is posted with a text area or text field and I am also using multi-dimensional arrays for the form field ids (e.g. name="blah[id][5]") the text that was posted in the text area or text field gets mysteriously truncated by PHP at 256 characters with ...cut... at the end of the string. It's definitely happening after the POST, before any other processing and before it's written to the database. I can't find any reference to ...cut... within the PHP source code and we're still unable to reliably reproduce the error. It does not happen all the time. Has anyone encountered this maddening little beast before? We're using Apache 2 and PHP 5.2.6 on CentOS.

Check $HTTP_POST_RAW and/or php://input on the server to see if those are affected as well, and then use something like HTTPFox (in the Mozilla addons repository) to see what's getting sent out on the wire from the client.
As well, see if something like mod_security is active in Apache, which can also re-write data long before it gets anywhere near PHP.

Related

$_POST is empty or truncated intermittently

We're seeing an issue that sounds identical to the one reported here:
Intermittent empty $_POST issue
I'm not sure if that question was ever resolved (but I don't have the ability to comment on that post).
It is an extjs form submitted thousands of times a day (json encoded data), with maybe 20 failures getting logged (to a text log we're keeping) each day. We're on Apache, PHP 5.3.14.
We've done extensive searches on users experiencing empty and truncated POST data and tried a number of things, including:
checking value of php://input (also empty/truncated)
checking/increasing config settings like post_max_size
explicitly setting content type
experimenting with keepalive settings
when data is truncated, it is seemingly random (not special characters)
the length of data POSTed doesn't seem to be a factor (truncates at random place, independent of how many fields are being POSTed back)
One potential clue is that when the POST comes back completely empty, it seems to always be with Internet Explorer or Safari. For the ones that are truncated, it doesn't appear to be specific to a particular browser (so it is possible that there are two separate problems at work here).
We're running out of ideas about what to try -- any ideas?
We found something in our app that could have been causing the problem. We had a menu that used javascript and it was doing a form submission, i.e. document.formname.submit(). People were clicking on the menu before the whole page was loaded. This submission had the potential to submit part of a form. This was a javascript HTML issue not server related.

AJAX / PHP not working on new WAMP server

We've moved a php page from one WAMP server to another and the chap who created it has left the business. I know nothing about AJAX, so am struggling!
I've scoured the code on both the old server and new, and it's exactly the same but for some reason the AJAX on the new server isn't working correctly, whereas on the old server it's fine.
What it's supposed to do is show a list of people from our database, allow users to update those records and then show the new, updated record without refreshing the page.
On the old server, it works a treat but on the new server it doesn't load the new data through. It's probably something ridiculously basic, but I'm scratching my head (mainly as I know nothing about the technology!)
Any help much appreciated.
Have you made sure the script that you are requesting with AJAX is actually there? You have said you've uploaded the script but is the path exactly the same? Different environments may have different paths to the same script.
Also how are you making the AJAX request? Are you using (for example) the jQuery library that might exist on one environment but not the other? Are they both using the same version of jQuery?
Use the Javascript console to see what errors you're getting and go from there. Chrome and Firefox have the best ones by default.
https://developer.mozilla.org/en/Error_Console
Before any of this though I would make sure the original script is working and returning the right results.
First check:
Look into the Javascript code and find where the actual URL is constructed.
It will look like:
xmlhttp.open("GET","yourAjaxPage.php",true);
but the xmlhttp can have a different name.
Now, simply alert this URL, or document.write(), or anything that gives you the url.
Put this URL into the browser-url and see the response.
In case you are using a session, make sure you use the same browser (TAB for example) where you expect the result.
Now you will see the response from the server to the request you just made. This should get you going finding the problem.
With the error console we were seeing an error 500 from the server (which seemed odd and rather unspecific...!)
Having had someone we know take a look at the code, it seems that on the old server, it seemed quite happy using mssql_close($con); but on the new server it didn't and so simply replacing it with sqlsrv_close($con) then meant the page the ajax was calling could complete and then returned the results as expected!
Always the little things...!

PHP automaticly parses my string?

Some Background info: My web application stores some XML in a Text column of the MySQL database. This XML represents a transaction for the application.
The problem occurs when I'm testing my library. Within PHP, I have a string:
$s="<flist><transaction amount=\"10\" type=\"income\">Initial Amount</transaction></flist>";
However, whenever I echo or consecrate this string, it turns into "Initial Amount". Am I missing a feature of PHP? How can I fix this? Wow! As I'm creating this post, StackOverflow is transforming that XML into $s=Initial Amount as well... Please help... Thank-you for your time as this completely perplexes me.
PHP doesn't automatically parse the string.
Are you echoing it and viewing it in a browser? It's very likely that the browser skips over the unknown tags and shows what it can. You might want to considering adding in htmlspecialchars() to your output like so:
echo htmlspecialchars($s);
You should also see it correctly when viewing the web source. This is a feature of HTML to support future versions without breaking current ones.

Passing variable to Google Charts URL

This is probably something really simple, however I am quite new to PHP, and havent done any HTML in years.
I need to get a PHP variable filled with an array of figures into Google Charts. My code for this so far is:
<img src="http://chart.apis.google.com/chart?
&chs=340x175
&chd=t:<?=$filedetail[1]?>
&cht=lc
&chtt=Test
">
However, Google reports an error, as it stops at the ?=$filedetail[1] for some reason. It doesnt seem that reading the variable is the problem, more that the API simply cant read past the start of the PHP tags.
Thanks,
Rob A.
EDIT: I have managed to make Google accept the URL, however now it is not showing anything on the chart, as its filling in the &chd=t: field with instead of the figures within that variable.
The URL reads like this:
http://chart.apis.google.com/chart?&chs=340x175&chd=t:%3C?=$filedetail[1]?%3E&cht=lc&chtt=Test
If oyu say Google is complaining about the ?=$filedetail, chances are you are doing this in a file that is not being parsed by PHP, for example a file that ends with .html or .htm.
You can see whether this is the case by looking into the page's source code in the browser. If you see the PHP command in the source as you wrote it above, the PHP code was never executed.
The easiest way to fix that, if that's the problem, would be to switch to a .php file extension.
In URLs, literal & should be written as &
Edit: And you can't do ?&chs -- it should be ?chs. The line breaks are probably going to break the URL too...

Strange PHP output corruption

I'm having a very strange output corruption on one of my PHP sites. Sometimes, a piece of HTML code is displayed, rather than the tags being interpreted. It looks like some characters are missing, messing up the tags. See the example below: the second line should just be a link to c1, but due to some reason part of the target URL is shown.
alt text http://trappist.elis.ugent.be/~wheirman/atuin/tmp/phpstrangeness.png
The problem is temporary, a refresh usually solves it. This can happen on different parts of the page (although often in the same location). Only Safari seems affected (but I'm suspecting Firefox just masks the problem due to more tolerant parsing). It happens on both my development server as the live one, they both have slightly different settings (output buffering, chunked transfer), although the probability of it happening seems to vary.
Anyone ever seen something like this??
EDIT
When I "View Source" in Safari on this page, I get the following HTML:
<tr class="odd">
<td>73</td>
<td>c1</td>
<td></td>
<td><img src='/images/dot_blue.png' class="altTooltip" alt="inactive: no account" /> </td>
I can't see anything wrong with this, so either Safari has reloaded the page when I asked it for the source, or I'm not looking hard enough...
Well, here's my shot in the dark.
The break occurs in the word "office", after the fi character combination. I would bet that the fi ligature is -- somehow -- causing trouble.
How exactly? Since that HTML code doesn't contain the ligature character, this might be a bug in Safari. Especially since it occurs randomly. Could you try to rename that file, and see if the problem goes away?
Having valid HTML might also help in avoiding this problem, because it makes parsing easier.
When you select a piece of HTML and view source, what you get is not 100% what is there. For instance, all of you &'s are &, which probably means you selected the offending text and viewed the selection's source.
If you are still having the issue, trying viewing the whole source code without selecting anything, and then using ctrl + f to find the spot in the code, and try and give us a larger sample, not just the offending row, but a correct row, and in a larger context.
For instance, when using tables, a mislaid <td> can have very weird consequences, this doesn't look like that type of issue, I am just saying that we need context to be able to help.
There's also the issue that some browsers, in order to view source, actually resubmit the page and get a second copy of it. I have a feeling that it is the code that's outputting the text, so look and see if you are using something like
<?= $someVar ?>
and make sure it's not like this:
'?>> xxx
So, no selecty, and bigger sample please. And we'd prolly need something from the code that outputs the errored HTML...
I finally found the problem (using Web Inspector): TinyMCE has been inserting tags (which it uses to load language files and extension modules), at seemingly random places inside my own HTML. The result was that, in the case visible from my screenshot, something like bar.php">foobar.
Since I'm also using jQuery on the same page, my guess is it was ultimately cause by jQuery's modifications to the DOM and TinyMCE's additions happening at the same time which resulted in some sort of race condition (caused by a bug that only appears to exhibit itself in Safari).
I am now using the jQuery build of TinyMCE, and all has been well since...
Thanks to everyone for the help!

Categories