php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38455 Data truncated when posting XML from one file to another.
Submitted: 2006-08-14 20:56 UTC Modified: 2006-08-15 15:18 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: powellsmith at yahoo dot com Assigned:
Status: Not a bug Package: URL related
PHP Version: 4.4.3 OS: Windows XP Pro
Private report: No CVE-ID: None
 [2006-08-14 20:56 UTC] powellsmith at yahoo dot com
Description:
------------
I am having a problem with posting data from one file to another. For some reason, the last few characters of my string variable keep getting dropped, so when it comes time to process the post, the data is not in tact.

xt_send.php

This file creates a variable and assigns the XML to the variable as string data. Then, I am opening up a connection on the same server to post the data in a variable called xml. I have also tried doing this in CURL. I am able to make successful requests on this machine all the time...this is the first time I've ever experienced this.


Reproduce code:
---------------
php:
-----------------------------------------------------------

$XT_xml = '<?xml version="1.0" encoding="UTF-8" ?>
   <XTMAILING>
   <CAMPAIGN_ID>14531</CAMPAIGN_ID>
   <TRANSACTION_ID>93</TRANSACTION_ID>
   <SAVE_COLUMNS>
     <COLUMN_NAME>Name</COLUMN_NAME>
     <COLUMN_NAME>Amount</COLUMN_NAME>
     <COLUMN_NAME>OrderID</COLUMN_NAME>
   </SAVE_COLUMNS>
  <RECIPIENT>
   <EMAIL><![CDATA[johndoe@xxxxxx.com]]></EMAIL>
   <BODY_TYPE>HTML</BODY_TYPE>
   <PERSONALIZATION>
     <TAG_NAME>Name</TAG_NAME>
     <VALUE><![CDATA[John Doe]]></VALUE>
   </PERSONALIZATION>
   <PERSONALIZATION>
     <TAG_NAME>from_name</TAG_NAME>
     <VALUE><![CDATA[Group]]></VALUE>
   </PERSONALIZATION>
   <PERSONALIZATION>
     <TAG_NAME>from_address</TAG_NAME>
     <VALUE><![CDATA[root@localhost]]></VALUE>
   </PERSONALIZATION>
   <PERSONALIZATION>
     <TAG_NAME>EMAIL_CONTENT_TEXT</TAG_NAME>
     <VALUE><![CDATA[Product<br />
------------------------------------------------------<br />
Order Number: 93<br />
Detailed Invoice: http://csweb01.atlc1/osc/account_history_info.php?order_id=93<br />
Date Ordered: Wednesday 02 August, 2006<br />
<br />
Products<br />
------------------------------------------------------<br />
1 x Hewlett Packard LaserJet 1100Xi (HPLJ1100XI) = $499.99<br />
2 x There\'s Something About Mary (DVD-TSAB) = $99.98<br />
------------------------------------------------------<br />
Sub-Total: $599.97<br />
Flat Rate (Best Way): $5.00<br />
Total: $604.97<br />
<br />
Delivery Address<br />
------------------------------------------------------<br />
John Doe<br />
12345 Test Road<br />
Atlanta, GA    30080<br />
United States<br />
<br />
Billing Address<br />
------------------------------------------------------<br />
John Doe<br />
12345 Test Road<br />
Atlanta, GA    30080<br />
United States<br />
<br />
Payment Method<br />
------------------------------------------------------<br />
Cash on Delivery<br />
<br />
]]></VALUE>
   </PERSONALIZATION>
   <PERSONALIZATION>
     <TAG_NAME>EMAIL_CONTENT</TAG_NAME>
     <VALUE><![CDATA[<table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td>This is a test.</td>
      </tr>
    </table>]]></VALUE>
   </PERSONALIZATION>
   <PERSONALIZATION>
     <TAG_NAME>Amount</TAG_NAME>
     <VALUE><![CDATA[604.97]]></VALUE>
   </PERSONALIZATION>
   <PERSONALIZATION>
     <TAG_NAME>OrderID</TAG_NAME>
     <VALUE><![CDATA[93]]></VALUE>
   </PERSONALIZATION>
  </RECIPIENT>
</XTMAILING>';

$host = 'xxx.xxx';

$sock = fsockopen ($host, 80, $errno, $errstr, 20);

  if (!$sock) {
    print('Could not connect to host:'.  $errno . $errstr);
    return (false);
  }
  
  $size = strlen($XT_xml);
  echo '<p>size: ' . $size . '</p>';
  fputs ($sock, 'POST /osc/xt_catch.php HTTP/1.1' . "\n");
  fputs ($sock, 'Host: ' .  $host . "\n");
  fputs ($sock, 'Content-type: application/x-www-form-urlencoded' . "\n");
  fputs ($sock, 'Content-length: ' .  $size . "\n");
  fputs ($sock, 'Connection: close' . "\n\n");
  fputs ($sock,  'xml=' . $XT_xml);
  $buffer = '';
  
  while (!feof ($sock)) {
    $buffer .= fgets ($sock);
  } 
  
  fclose ($sock);

echo '<pre>';
echo htmlspecialchars($XT_xml);
echo '<BR><BR><BR><BR><BR>';
echo htmlspecialchars($result);
echo '</pre>';


-----------------------------------------------------------




Expected result:
----------------
-----------------------------------------------------------

<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<XTMAILING>
<CAMPAIGN_ID>14531</CAMPAIGN_ID>
<TRANSACTION_ID>93</TRANSACTION_ID>
<SAVE_COLUMNS>
<COLUMN_NAME>Name</COLUMN_NAME>
<COLUMN_NAME>Amount</COLUMN_NAME>
<COLUMN_NAME>OrderID</COLUMN_NAME>
</SAVE_COLUMNS>
<RECIPIENT>
<EMAIL><![CDATA[johndoe@xxxxxx.com]]></EMAIL>
<BODY_TYPE>HTML</BODY_TYPE>
<PERSONALIZATION>
<TAG_NAME>Name</TAG_NAME>
<VALUE><![CDATA[John Doe]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>from_name</TAG_NAME>
<VALUE><![CDATA[Group]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>from_address</TAG_NAME>
<VALUE><![CDATA[root@localhost]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>EMAIL_CONTENT_TEXT</TAG_NAME>
<VALUE><![CDATA[Product<br />
------------------------------------------------------<br />
Order Number: 93<br />
Detailed Invoice: http://xxx.xxx/osc/account_history_info.php?order_id=93<br />
Date Ordered: Wednesday 02 August, 2006<br />
<br />
Products<br />
------------------------------------------------------<br />
1 x Hewlett Packard LaserJet 1100Xi (HPLJ1100XI) = $499.99<br />
2 x There\'s Something About Mary (DVD-TSAB) = $99.98<br />
------------------------------------------------------<br />
Sub-Total: $599.97<br />
Flat Rate (Best Way): $5.00<br />
Total: $604.97<br />
<br />
Delivery Address<br />
------------------------------------------------------<br />
John Doe<br />
12345 Test Road<br />
Atlanta, GA 30080<br />
United States<br />
<br />
Billing Address<br />
------------------------------------------------------<br />
John Doe<br />
12345 Test Road<br />
Atlanta, GA 30080<br />
United States<br />
<br />
Payment Method<br />
------------------------------------------------------<br />
Cash on Delivery<br />
<br />
]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>EMAIL_CONTENT</TAG_NAME>
<VALUE><![CDATA[<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>This is a test</td>
</tr>
</table>]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>Amount</TAG_NAME>
<VALUE><![CDATA[604.97]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>OrderID</TAG_NAME>
<VALUE><![CDATA[93]]></VALUE>
</PERSONALIZATION>
</RECIPIENT>
</XTMAILING>



-----------------------------------------------------------

Actual result:
--------------
-----------------------------------------------------------

<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<XTMAILING>
<CAMPAIGN_ID>14531</CAMPAIGN_ID>
<TRANSACTION_ID>93</TRANSACTION_ID>
<SAVE_COLUMNS>
<COLUMN_NAME>Name</COLUMN_NAME>
<COLUMN_NAME>Amount</COLUMN_NAME>
<COLUMN_NAME>OrderID</COLUMN_NAME>
</SAVE_COLUMNS>
<RECIPIENT>
<EMAIL><![CDATA[johndoe@xxxxxx.com]]></EMAIL>
<BODY_TYPE>HTML</BODY_TYPE>
<PERSONALIZATION>
<TAG_NAME>Name</TAG_NAME>
<VALUE><![CDATA[John Doe]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>from_name</TAG_NAME>
<VALUE><![CDATA[Group]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>from_address</TAG_NAME>
<VALUE><![CDATA[root@localhost]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>EMAIL_CONTENT_TEXT</TAG_NAME>
<VALUE><![CDATA[Product<br />
------------------------------------------------------<br />
Order Number: 93<br />
Detailed Invoice: http://xxx.xxx/osc/account_history_info.php?order_id=93<br />
Date Ordered: Wednesday 02 August, 2006<br />
<br />
Products<br />
------------------------------------------------------<br />
1 x Hewlett Packard LaserJet 1100Xi (HPLJ1100XI) = $499.99<br />
2 x There\'s Something About Mary (DVD-TSAB) = $99.98<br />
------------------------------------------------------<br />
Sub-Total: $599.97<br />
Flat Rate (Best Way): $5.00<br />
Total: $604.97<br />
<br />
Delivery Address<br />
------------------------------------------------------<br />
John Doe<br />
12345 Test Road<br />
Atlanta, GA 30080<br />
United States<br />
<br />
Billing Address<br />
------------------------------------------------------<br />
John Doe<br />
12345 Test Road<br />
Atlanta, GA 30080<br />
United States<br />
<br />
Payment Method<br />
------------------------------------------------------<br />
Cash on Delivery<br />
<br />
]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>EMAIL_CONTENT</TAG_NAME>
<VALUE><![CDATA[<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>This is a test</td>
</tr>
</table>]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>Amount</TAG_NAME>
<VALUE><![CDATA[604.97]]></VALUE>
</PERSONALIZATION>
<PERSONALIZATION>
<TAG_NAME>OrderID</TAG_NAME>
<VALUE><![CDATA[93]]></VALUE>
</PERSONALIZATION>
</RECIPIENT>
</XTMAIL


-----------------------------------------------------------
(i.e., last four chars are truncated and XML becomes invalid)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-14 21:32 UTC] tony2001@php.net
>Content-type: application/x-www-form-urlencoded
That's also a hint to you: use urlencode();
 [2006-08-15 15:18 UTC] powellsmith at yahoo dot com
Problem solved.  In the php, you'll see that we are calculating the string length before appending the 'xml=' to the beginning of the string.  Hence, the reason it is truncated by 4 chars.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 05:01:28 2024 UTC