#38970 [NEW]: weird skip so that $array[0] is missed
| From: | jlindenbaum at gawsolutions dot com | Date: | Wed, 27 Sep 2006 03:00:08 +0000 |
| Subject: | #38970 [NEW]: weird skip so that $array[0] is missed | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-102780@lists.php.net to get a copy of this message | ||
From: jlindenbaum at gawsolutions dot com
Operating system: Cent OS 4.2
PHP version: 4.4.4
PHP Bug Type: Scripting Engine problem
Bug description: weird skip so that $array[0] is missed
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 bug report at http://bugs.php.net/?id=38970&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38970&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38970&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38970&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38970&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=38970&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38970&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38970&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38970&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38970&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38970&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=38970&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=38970&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38970&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38970&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38970&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38970&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38970&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38970&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38970&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38970&r=mysqlcfg