#3449 [Com]: Form method POST doesn't work properly
| From: | nando at aboutown dot ca | Date: | Thu, 19 Sep 2002 05:46:19 +0000 |
| Subject: | #3449 [Com]: Form method POST doesn't work properly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-19701@lists.php.net to get a copy of this message | ||
ID: 3449
Comment by: nando@aboutown.ca
Reported By: heep@cnetworks.net
Status: Closed
Bug Type: Scripting Engine problem
Operating System: FreeBSD 2.2.8-STABLE
PHP Version: 4.0 Latest CVS (10/02/2000)
New Comment:
I have the same problem.
When I have a hidden input with long text,
the text was never sent (from the host) completely to
the client.
My experience is the first 5 or 6 characters are sent
and it is cut off.
I have spent 3 days trying to program around this and
it is frustrating.
Previous Comments:
------------------------------------------------------------------------
[2000-06-19 19:06:34] rasmus@cvs.php.net
If this still happens with the current code, please re-open this report
or resubmit.
I cannot reproduce it. Grab a snapshot from http://snaps.php.net
and
test it.
------------------------------------------------------------------------
[2000-02-10 16:40:07] heep@cnetworks.net
<hr>
Script "post.php3" which illustrate the problem
<?
echo "<HTML><TITLE>Post Method Test</TITLE>";
echo "<BODY>";
echo "<FORM name=test action=post.php3 METHOD=POST>";
if ($act==''){
$file = fopen("test.txt", "r");
if (!$file) {
echo "<p>Unable to open remote file.\n";
exit;
}
while (!feof($file)) {
$tx = fgets($file, 1024);
$txt=$txt.$tx;
}
$txt=addslashes($txt);
fclose($file);
$lgth=strlen($txt);
echo "<BR>Read: length=$lgth";
echo "<hr>";
}
if ($act=='post'){
$lgth=strlen($txt);
echo "<BR>Read: length=$lgth";
}
echo "<BR>act=$act";
echo "<BR><INPUT type=hidden name=act value=post>";
echo "<BR><TEXTAREA rows=10 cols=50 name='txt' align=top
>$txt</TEXTAREA>";
echo "<BR><INPUT type=submit value='Send'>";
echo "<INPUT type=reset value='Clear'>";
echo "</FORM>";
echo "</BODY>";
echo "</HTML>";
?>
<hr>
Error description:
When I send long enough text from the form text area, it
cutted somewhere in the middle and last character is "%".
It is also clear that if string
echo "<BR><INPUT type=hidden name=act value=post>";
will be set after string
echo "<INPUT type=reset value='Clear'>";
than value of $act will be empty. To my view there is
overwriting some internal buffer in PHP occures when variable
filled up by content of POST
All works Ok with PHP 3.0
file which I use can be almost any or you can type content of the form
by hand (but how much characters I don't know, suppose few kilobytes :)
I get content for file from PHP help system.
<hr>
test file "text.txt" and its content:
LII. String functions
These functions all manipulate strings in various
ways. Some more specialized sections can be
found in the regular expression and URL handling
sections.
Table of Contents
AddCSlashes Quote string with slashes in a C
style
AddSlashes Quote string with slashes
bin2hex Convert binary data into hexadecimal
representation
Chop remove trailing whitespace
Chr Return a specific character
chunk_split Split a string into smaller chunks
convert_cyr_string Convert from one Cyrillic
character set to another
crypt DES-encrypt a string
echo Output one or more strings
explode Split a string by string
flush Flush the output buffer
get_html_translation_table Returns the
translation table used by htmlspecialchars()
and htmlentities()
get_meta_tags Extracts all meta tag content
attributes from a file and returns an array
htmlentities Convert all applicable characters
to HTML entities
htmlspecialchars Convert special characters to
HTML entities
implode Join array elements with a string
join Join array elements with a string
ltrim Strip whitespace from the beginning of a
string
md5 Calculate the md5 hash of a string
Metaphone Calculate the metaphone key of a
string
nl2br Converts newlines to HTML line breaks.
Ord Return ASCII value of character
parse_str Parses the string into variables
print Output a string
printf output a formatted string
quoted_printable_decode Convert a
quoted-printable string to an 8 bit string
QuoteMeta quote meta characters
rawurldecode Decode URL-encoded strings
rawurlencode URL-encode according to RFC1738
setlocale Set locale information
similar_text Calculate the similarity between
two strings
soundex Calculate the soundex key of a string
sprintf Return a formatted string
strcasecmp Binary safe case-insensitive string
comparison
strchr Find the first occurrence of a character.
strcmp Binary safe string comparison
strcspn Find length of initial segment not
matching mask
strip_tags Strip HTML and PHP tags from a
string
StripCSlashes un-quote string quoted with
addcslashes
StripSlashes Un-quote string quoted with
addslashes
stristr Case-insensitive strstr()
strlen Get string length
strpos Find position of first occurrence of a
string
strrchr Find the last occurrence of a character
in a string
str_repeat Repeat a string
strrev Reverse a string
strrpos Find position of last occurrence of a
char in a string
strspn Find length of initial segment matching
mask
strstr Find first occurrence of a string.
strtok Tokenize string
strtolower Make a string lowercase
strtoupper Make a string uppercase
str_replace Replace all occurrences of needle in
haystack with str
strtr Translate certain characters
substr Return part of a string
substr_replace Replace text within a portion of
a string.
trim Strip whitespace from the beginning and end
of a string
ucfirst Make a string's first character
uppercase
ucwords Uppercase the first character of each
word in a string
User Contributed Notes: String functions
Manuel@Hossfeld.de
19-Mar-1999 06:03
One important thing to be
aware of when dealing with strings is
the meaning of special
character sequences and the difference
between using <I>single
quotes</I> and <I>double
quotes</I>.
A "normal" string assignment
looks like this:
$str = "Some string...";
As you probably already
noticed elsewhere in this manual you
could also use
$name = "Joe";
$str = "Hello $name"; //
results in "Hello Joe"
Now it gets a bit tricky:
If your string contains
certain special character sequences
beginning with a backslash
(often referred to as "escape
sequences" or "control codes"
or similar), PHP will evaluate
them and act accordingly. The
most useful control codes are \t
and \n. \t results in a "TAB",
while \n inserts a newline.
So...
echo "Hello $name\nWelcome
to\twonderland"
Will give something like
Hello Joe
Welcome to wonderland
(Naturally, it won't show up
this way in your browser unless its
inside a <PRE>
</PRE> block.)
Of course, if you already know
any other language like C or
JAVA, all this won't tell you
anything new.
There is a pitfall however,
that when e.g. you want to store
Windows paths in a string
and/or output it the behavior above
may bite you. Example:
$win_path =
"c:\test\mytext.txt";
echo $win_path;
This will look like
c: est\mytext.txt
in the HTML code PHP
generates, because it really means
"c:(TAB)\mytext.txt"! Since
this is probably not what you
intended, you should use
single quotes in this case:
$win_path =
'c:\test\mytext.txt';
The single quotes will ensure
that PHP treats this string
verbatim, so the \t in this
example wouldn't result in a TAB. Be
aware that this also prevents
PHP from expanding any variables,
so
echo 'Hello $name'; //
this outputs Hello $name !
doesn't work as you might
expect.
Another means of preventing
special character sequences from
being evaluated is "escaping"
them. (BTW: This concept is also
found in many other
languages.) What does this mean? In the
above example we could've also
written:
$win_path =
"c:\\test\mytext.txt";
echo $win_path; //
outputs c:\test\mytext.txt
This effectively tells PHP not
to interpret the \t as a TAB.
Accordingly, the same goes for
\\n etc.
Now you may ask "Argh, do I
have to really take care of this
myself - Why can't PHP do it
for me?"
The answer is yes, it can:
Just use the <I>addslashes()</I>
function. If you want to know
more about it, read the
appropriate section.
improv@magma.ca
19-Aug-1999 10:08
two functions missing from this
list:
// Function: rpad
//
***********************************
// Purpose: right pad a string
to a specified length,
// or trim it to that
length if too long
// Inputs: $inStr - String to
be padded
// $len - length of
desired out put string
// $with - [optional]
character(s) to use in padding
// (defaults
to space " ")
// To Do: improper input
error handling
//
***********************************
function rpad($inStr, $len,
$with = " ") {
// if inStr needs
padding
if (strlen($inStr) <
$len) {
$outStr =
$inStr; // output string
// make sure
$inStr + $with isn't longer than $len
if
((strlen($inStr) + strlen($with)) < $len) {
// add
$with as many times as it will fit
for
($i=strlen($inStr);$i<$len;$i+=strlen($with)) {
$outStr .= $with;
}
}
// if its still
not long enough
if
(strlen($outStr) != $len) {
// tack
on a enough of $with to make up the difference
$outStr
.= substr($with,0,($len-strlen($outStr)));
}
// off to the
races
return
$outStr;
}
else {
// shrink it
down
return
substr($inStr,0,$len);
}
}
// Function: lpad
//
***********************************
// Purpose: left pad a string
to a specified length,
// or trim it from
the right to that length
// if too long
// Inputs: $inStr - String to
be padded
// $len - length of
desired out put string
// $with - [optional]
character(s) to use in padding
// (defaults
to space " ")
// To Do: improper input
error handling
//
***********************************
function lpad($inStr, $len,
$with = " ") {
// if inStr needs
padding
if (strlen($inStr) <
$len) {
$rStr = $inStr;
// the string to be padded
$lStr = "";
// the padding
// make sure
$inStr + $with isn't longer than $len
if
((strlen($inStr) + strlen($with)) < $len) {
// add
$with to the padding as many times as it will fit
for
($i=strlen($inStr);$i<$len;$i+=strlen($with)) {
$lStr .= $with;
}
}
// stick the
values together
$outStr = $lStr
. $rStr;
// if its still
not long enough
if
(strlen($outStr) != $len) {
// tack
on a enough of $with to the middle to make up the difference
$outStr
= $lStr . substr($with,0,($len-strlen($outStr))) . $rStr;
}
// off to the
races
return
$outStr;
}
// $inStr too long
else {
// shrink it
down (chopping off the left most chars.)
return
substr($inStr,-$len);
}
}
kris@mha.ca
21-Sep-1999
07:09
lpad and rpad are unnecssary as
<A
HREF="http://www.php.net/manual/function.sprintf.php3">sprintf<A>
will do all that and much more...
Kris
zarkdav+php@eddy.easynet.fr
08-Oct-1999 02:10
How do you pad a
string with n characters using
sprintf? I tried the
single-quote ' modifier, with no
result.
ptomblin@xcski.com
12-Oct-1999 05:10
How do I word wrap some text?
I get some text in from a text
area on a form, and it's
nicely word wrapped on the screen. But
as soon I go to email it to
somebody, it's all one big long text
string with no returns. It
would be nice if there was a function
similar to the unix command
"fmt".
waltb@rocketcash.com
08-Nov-1999 02:11
How can I upper case an
entire string? This is useful when
preparing a string for
database access, where converting the
string in the db query
hinders performance.
ptomblin@xcski.com
12-Nov-1999 11:11
A quick and dirty function to
wrap text at a given wrap margin:
function wraptext($text,
$wrapmargin)
{
$rettext = "";
$linebuf = "";
$linelen = 0;
$tok = split("[ \t]",
$text);
$numtok = count($tok);
for ($i = 0; $i < $numtok;
$i++)
{
$elem = $tok[$i];
$elemlength =
strlen($elem) + 1;
if ($linelen +
$elemlength > $wrapmargin)
{
$rettext =
$rettext . $linebuf . "\n";
$linebuf = "";
$linelen = 0;
}
// Do we have a
newline in this element?
$pos = strrpos($elem,
"\n");
if ($pos)
{
$before =
substr($elem, 0, $pos);
$after =
substr($elem, $pos);
$rettext =
$rettext . $linebuf . " " . $before . "\n";
$linebuf =
$after;
$linelen =
strlen($after);
}
else
{
$linebuf =
$linebuf . " " . $elem;
$linelen =
$linelen + $elemlength;
}
}
// Do we have a
newline in this element?
$pos = strrpos($elem,
"\n");
if ($pos)
{
$before =
substr($elem, 0, $pos);
$after =
substr($elem, $pos);
$rettext =
$rettext . $linebuf . " " . $before . "\n";
$linebuf =
$after;
$linelen =
strlen($after);
}
else
{
$linebuf =
$linebuf . " " . $elem;
$linelen =
$linelen + $elemlength;
}
}
return $rettext;
}
fgmp@yahoo.com
16-Jan-2000 05:01
Is there a way to print huge
chunks of html without having the
escape every damn double quote?
I can do this in perl with print
qq( ALL THE HTML TAGS YOU CAN
THINK OF WITH UNESCAPED
QUOTES ); Is ther something
simillar to qq(); in php?
elliot@rightnowtech.com
27-Jan-2000 07:01
to fgmp@yahoo.com: you
should break out of php for large
bits of html. not only is
it easier, but much much faster
compared to echoing or
printfing everything. and <? } ?>
is perfectly acceptable to
php as well.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=3449&edit=1