foreach construct problems
Posted: Tue Aug 24, 2004 3:02 am
feyd | Please use
=====================================================================================
When I run this script, it returns the "$user is not a valid user on this sytem" error.
Here is the output of the script after trying to change my own passwd:
=====================================================================================
=====================================================================================
What am I doing wrong???
PLease help this clueless newbie.
Thanks
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
HI,
I have a file called /tmp/usrlist containing a list of valid users. I am writing an admin interface to the server and one of the functionalities is to change users password. Now information is entered into a form and passed on to script changepasswd.php which checks tah it is not root, compares the username with /tmp/usrlist and changes the password. Well that is what is suposed to happen anyway. Instead it seems like the foreach construct isn't doing it's job.
I added a var_dump and the array is filled correctly but the comparrison doesn't seem to work:
=====================================================================================Code: Select all
<?php
include('header.php');
//create short variable names
$user = $HTTP_POST_VARS['user'];
$pw = $HTTP_POST_VARS['pw'];
$pwcf = $HTTP_POST_VARS['pwcf'];
//check if the passwords match, user is not root, is a valid system user, and execute that change password script
if ($user == "root")
{
echo("You are not authorised to change Root's password");
}
$users= file("/tmp/usrlist");
echo '<pre>';
echo var_dump($users);
echo '</pre>';
if ($pw == $pwcf)
{
$fp = fopen("/tmp/chpasswd", 'w');
$output = $user.":".$pw;
$match = "no";
foreach ($users AS $validName) {
if($user == $validName) { $match = "yes"; }
}
if ($match == "yes") {
fwrite($fp, $output );
exec(escapeshellcmd("./chpasswd.sh" ));
}
else {
echo("$user is not a valid user on this system");
}
}
else
{
echo("The passwords do not match, please try again");
}When I run this script, it returns the "$user is not a valid user on this sytem" error.
Here is the output of the script after trying to change my own passwd:
=====================================================================================
Code: Select all
array(3) {
ї0]=>
string(7) "nobody
"
ї1]=>
string(4) "jls
"
ї2]=>
string(8) "juanita
"
}
jls is not a valid user on this systemWhat am I doing wrong???
PLease help this clueless newbie.
Thanks
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]