#38970 [Opn->Fbk]: weird skip so that $array[0] is missed
| From: | derick@php.net | Date: | Wed, 27 Sep 2006 07:07:03 +0000 |
| Subject: | #38970 [Opn->Fbk]: weird skip so that $array[0] is missed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-102786@lists.php.net to get a copy of this message | ||
ID: 38970
Updated by: derick@php.net
Reported By: jlindenbaum at gawsolutions dot com
-Status: Open
+Status: Feedback
Bug Type: Scripting Engine problem
Operating System: Cent OS 4.3
PHP Version: 4.4.4
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
Previous Comments:
------------------------------------------------------------------------
[2006-09-27 03:07:52] jlindenbaum at gawsolutions dot com
Sorry, another update. We just found the weirdest work around.
the echo the checkbox:
echo "\t<input type=\"checkbox\" name=\"1".$key."\"
value=\"".$value."\" /> ".$value
if we add the one before the $key in nam="" so that the $_POST array
starts at 10 it works fine.
------------------------------------------------------------------------
[2006-09-27 03:05:06] jlindenbaum at gawsolutions dot com
Sorry entered wrong OS version. Changed from 4.2 to 4.3
------------------------------------------------------------------------
[2006-09-27 03:00:07] jlindenbaum at gawsolutions dot com
Description:
------------
Reading files from a directory, stripping "." and "..". Sorting array
by values (using sort()). foreach() is used to output a checkbox for
each file (cPanel user file).
When user is checked chosen action (from the radio buttons) is to be
applied (with system command) by executing the command in action with
the appropriate username trailing.
foreach() is used to go through every $_POST value with an if() the
$keys "action" and "submit" are excluded from execution. A bash command
is put together and finally executed.
Everything works as it should, except that the array[0] is totally
ignored.
Reproduce code:
---------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>User actions</title>
</head>
<body>
<form name="userlist" action="test.php" method="post">
<input type="radio" name="action" value="/scripts/pkgacct"
checked="checked" />Backup
<input type="radio" name="action" value="/scripts/suspendacct"
/>Suspend
<input type="radio" name="action" value="/scripts/unsuspendacct"
/>Unsuspend
<input type="radio" name="action" value="/scripts/killacct"
/>Delete
<br />
<?php
$handle = opendir("/var/cpanel/users/");
$usrarr = array(); // Array full of users
while( FALSE !== ($users = readdir($handle)) ) {
if( $users != "." && $users != ".." ) {
$usrarr[] = $users;
}
}
sort($usrarr); // sort alphabetically
foreach($usrarr as $key => $value) {
echo "\t<input type=\"checkbox\" name=\"".$key."\"
value=\"".$value."\" /> ".$value."<br />\n";
}
closedir($handle);
?>
<input name="submit" type="submit" id="submit"
value="GO">
</form>
<?php
if( isset($_POST['submit']) ) {
echo "<hr noshade=\"noshade\" />"; // output a horizontal rule for
clearance
echo "<pre>";
foreach( $_POST as $key => $value ) {
if( $key != "submit" && $key != "action" ) {
$bash = $_POST['action']." ".$value; // put together /path/command
username
echo "Processing: ".$value."<br />\n";
system($bash);
echo "Done<br />\n";
}
}
echo "<pre>";
}
?>
</body>
</html>
Expected result:
----------------
Expected result is that every $_POST key (0 through n) should be put
together with the $_POST['action'] command and a username, executed and
on to the next.
Actual result:
--------------
It works for every user, BUT the $usrarr[0] key and value.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38970&edit=1