RE: [PHP] Re: homemade authentication function [SOLVED]
| From: | Sævar Öfjörð | Date: | Wed, 23 Jul 2003 10:43:41 +0000 |
| Subject: | RE: [PHP] Re: homemade authentication function [SOLVED] | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-156426@lists.php.net to get a copy of this message | ||
Hey, thanks Sven. This seems to be working for me.
-----Original Message-----
From: sven [mailto:svenie@gmx.li]
Sent: 23. júlí 2003 10:35
To: php-general@lists.php.net
Subject: [PHP] Re: homemade authentication function
i think the problem isn't only your 'return false' but also your 'return
true' in your first loop through your foreach will definetly a 'return'
be
passed. and return means return a value AND stop the function. not?
try it this way:
foreach ($groups as $value)
{
if(!isset($this->user['groups'][$value]) ||
!$this->user['groups'][$value])
{
return false;
}
}
return true;
ciao SVEN
SævË Ölêöyp wrote:
> I'm making an authentication script with groups and roles. This
> function checks if the groups the user belongs to specified groups
> and compares them to the groups required. However, since this is a
> loop, the function doesn't return true or false as expected. If I
> call the function and require 3 groups, and the user belongs to only
> one of them, he is still accepted. Is this method right thinking?
> Should I make the function stop somehow when it returns false for the
> first time? All suggestions and comments are appreciated. Thanks.
>
> This is the function:
>
> function require_groups() {
> if (!isset($this->user['groups'])) {
> $this->user['groups'] =
> $this->get_user_groups($this->id);
> }
> $groups = func_get_args();
> foreach ($groups as $value) {
> if
> (!isset($this->user['groups'][$value]) ||
> !$this->user['groups'][$value]) {
> return false;
> }
> else{
> return true;
> }
> }
> }
>
> And I call it like this: require_groups("admins",
> "moderators","members");
> This returns true.
>
> Kveðja,
> Sævar Öfjörð
> ofjord@reddast.is
> þetta reddast - hönnunarlausnir
>
>
<file:///C:\Documents%20and%20Settings\S%E6var\Application%20Data\Micros
> oft\Signatures\www.reddast.is> www.reddast.is
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php