php3-list | 199903
Date: 03/18/99
- Next message: Dave Walton: "Re: [PHP3] Semi-OT: The Linux plunge"
- Previous message: Sander Pilon: "RE: [PHP3] OT: Dedicated servers"
- In reply to: Ronny Haryanto: "Re: [PHP3] PHP script to add users to .htpasswd"
- Next in thread: CDI: "Re: [PHP3] PHP script to add users to .htpasswd"
- Reply: CDI: "Re: [PHP3] PHP script to add users to .htpasswd"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Thanks for the suggestion! Ok, I modified my function and now it looks like:
function valid_name($user) {
$file = file(".htpasswd");
$count = count($file);
$retval = true;
$i=0;
while ($i<$count) {
$split = split(":",$file[$i]);
if($split[0] == $user) {
$retval = false;
break;
}
++$i
}
return $retval;
}
So, if this function returns a true value, the rest of the script should
proceed:
if (valid_name($user)) {
...rest of script here....
}
However whenever I run the script it always returns a 'true' value, even
when I try to use a username I know already exists in the .htpasswd file. I
discovered this by echoing the return value of the function and it always
shows '1'. What am I doing wrong here?
I look forward to your reply
Thanks,
Vamsi
php <email protected>
At 12:42 AM 3/18/99 -0600, you wrote:
>FYI, you can peek the source of class.Htpasswd.php3 from
>http://thewebmasters.net/php/
>
>On Thu, Mar 18, 1999 at 01:09:21AM -0500, Vamsi Nath wrote:
>> $tf = <email protected>(".htpasswd", "a+");
>> $file = file(".htpasswd");
>> $count = count($file);
>if you're doing file(), what do you need the $tf for?
>
>> if (ereg("$user","$split[0]")):
>change this to something like
>if($split[0] == $user):
>
>
>> elseif ($i == $count):
>> echo "false";
>these two lines doesn't make any sense to me.
>
>This is pretty much what I use:
>
>function valid_user($user)
>{
> $retval = false;
> if(!($fd = <email protected>($userfile,"r")))
> {
> echo "cannot open userfile";
> exit;
> }
> while($pwent= <email protected>($fd,80))
> {
> /* you don't need this if you're not doing
> * anything with the password */
> $pwent=trim(ereg_replace("\n","",$pwent));
>
> if(ereg("^(#|$)",$pwent)) # ignore comments and blanks
> continue;
> $entry = split(":",$pwent);
> if($entry[0]==$user)
> {
> $retval = true;
> break;
> }
> }
> fclose($fd);
> return $retval;
>}
>
-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>
- Next message: Dave Walton: "Re: [PHP3] Semi-OT: The Linux plunge"
- Previous message: Sander Pilon: "RE: [PHP3] OT: Dedicated servers"
- In reply to: Ronny Haryanto: "Re: [PHP3] PHP script to add users to .htpasswd"
- Next in thread: CDI: "Re: [PHP3] PHP script to add users to .htpasswd"
- Reply: CDI: "Re: [PHP3] PHP script to add users to .htpasswd"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

