ID: 38970 User updated by: jlindenbaum at gawsolutions dot com Reported By: jlindenbaum at gawsolutions dot com Status: Open Bug Type: Scripting Engine problem -Operating System: Cent OS 4.2 +Operating System: Cent OS 4.3 PHP Version: 4.4.4 New Comment:
Sorry entered wrong OS version. Changed from 4.2 to 4.3 Previous Comments: ------------------------------------------------------------------------ [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