我正在尝试使用此功能检查用户是否属于称为出纳员的组。我似乎做错了
function isMember($userid,$group){
$privGroups = array('Administrator', 'Super Users'); // Always return true for these
if(is_array($group))$mygroup = $group;
else $mygroup[0]=$group;
$j=0;
$n=count($mygroup);
for($i=count($mygroup); $i<($n+count($privGroups)); $i++) {
$mygroup[$i] = $privGroups[$j]; // Add "always" admins to argument admins
$j++;
}
// DB access credentials: $db, $dbhost, $login, and $pw need to be defined here
$link = mysql_connect($this->DB_HOST, $this->DB_USER, $this->DB_PASS)
or die("Could not connect : " . mysql_error());
mysql_select_db($this->DB_NAME) or die("Could not select database");
// extract all groups user's a member of
$query = "Select q.title FROM (#__user_usergroup_map as p)
LEFT JOIN (#__usergroups as q)
on p.group_id=q.id
WHERE p.user_id=$userid;";
// remove prefix etc.
$SQL = $this->cleanSQL($query);
$res=mysql_query($SQL) or die('<p>Groups select query failed<br />' . mysql_error() . "<br />$SQL</p>");
if (mysql_num_rows($res) == 0) { // No groups? Then user clearly isn't a mamber of "$group"
if($termlink) mysql_close($link);
return false;
}
while ($line = mysql_fetch_array($res, MYSQL_ASSOC)) {
extract($line);
$userGroups[]=$title;
}
mysql_close($link); // Close link
for($i=0; $i<count($userGroups); $i++){
for($j=0; $j<count($mygroup); $j++) {
if(strtolower($userGroups[$i])==strtolower($mygroup[$j])) return true;
}
}
return false;
}
这不起作用;它从某个地方失败了。如果成员是给定组的一部分,是否有快捷方式来检查?