php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34056 Passing a string variable results in incorrect length
Submitted: 2005-08-09 20:40 UTC Modified: 2005-10-09 19:13 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: David at Caulkett dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.11 OS: Linux 2.4.22-1.2199.nptlsmp
Private report: No CVE-ID: None
 [2005-08-09 20:40 UTC] David at Caulkett dot com
Description:
------------
Actually PHP is version 4.3.10.
Passing a string variable from test1 to test2 works fine.  Passing the same string from test2 to test3 results in an incorrect length.  The length is 30 greater than it should be.  PHP seems to be padding the string with 30 spaces which is likely the length of the original INPUT statement.  The problem is fixed by removing the extra spaces with the trim function.

The test programs are at:
http://www.reportillegals.com/test1.php
http://www.reportillegals.com/test2.php
http://www.reportillegals.com/test3.php

The source of the programs are at:
http://www.reportillegals.com/test1.txt
http://www.reportillegals.com/test2.txt
http://www.reportillegals.com/test3.txt





Reproduce code:
---------------
TEST1 CODE:
<html>
<body>
<form method="POST" name="emailcomments" action="http://www.reportillegals.com/test2.php">
  <input type="text" name="User_Email_Address" >
  <input type="submit" value="PHP Bug Test1 - Enter email address and remember the no. of chars">
</form>
</body>
</html>

TEST2 CODE:
<html>
<body>
<?php
$length = strlen ( $User_Email_Address );
echo "length=" . $length;
?>
<form method="POST" name="emailcomments" action="http://www.reportillegals.com/test3.php">
<input type="hidden" name="User_Email_Address" value="
              <?php print $User_Email_Address;?>
              ">
   <input type="submit" value="PHP Bug Test2 - Length should be what you just entered. Just click Submit">
</form>
</body>
</html>

TEST3 CODE:
<html>
<body>
<?php
$length = strlen ( $User_Email_Address );
echo "length=" . $length ."<br>";
echo "length is incorrect.  it is whatever you entered +30" . "<br>";
$User_Email_Address = trim ($User_Email_Address);
$length = strlen ( $User_Email_Address );
echo "length=" . $length ."<br>";
echo "length is now correct after using the trim function.". "<br>";
?>
</body>
</html>

Expected result:
----------------
The length in test2 and test3 should be the same number of characters as entered in test1.

Actual result:
--------------
The length is whatever was entered + 30.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-09 15:17 UTC] David at Caulkett dot com
The problem ocurred on a server handled by http://support.coastinc.com/  PHP version is 4.3.10 .

I am unable to provide a snapshot of the server.

The test case is simple and hard demonstrable at http://www.reportillegals.com/test1.php.  

IMHO, either PHP has a bug or the PHP installation is bad.  My guess is there is a PHP bug.
 [2005-10-09 16:40 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Either you try the snapshot or provide short example script.
(one file only!!)

 [2005-10-09 17:23 UTC] David at Caulkett dot com
The problem has to do with passing of arguments from one page to another using POST.  Therefore it is difficult to condense a demonstration to ONE file.  However, I did provide the simple example code showing the sequence in ONE file.

I spent a great deal of time narrowing the problem to a simple test case. The example code was provided in ONE FILE but requires BY THE NATURE OF THE PROBLEM to be executed over several pages in order to demonstrate the problem.

It is not possible to provide a snapshot and I can't make it much simpler in ONE FILE as shown under "Reproduce Code."
 [2005-10-09 19:13 UTC] sniper@php.net
You do know that you can post to same file too? :)
Try using the preferred way of coding, ie. using $_GET, $_POST , etc. instead of requiring register_globals=On.

Reopen when you have such script (that does not require register_globals=On) and that we can cut'n'paste easily OR download somewhere in ONE file.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 10:01:32 2024 UTC