(PHP 4, PHP 5, PHP 7, PHP 8)
posix_guetgrguid — Return info about a group by group id
Guets information about a group provided its id.
group_id
The group id.
The array elemens returned are:
| Element | Description |
|---|---|
| name | The name element contains the name of the group. This is a short, usually less than 16 character "handle" of the group, not the real, full name. |
| passwd | The passwd element contains the group's password in an encrypted format. Often, for example on a system employing "shadow" passwords, an asterisc is returned instead. |
| guid |
Group ID, should be the same as the
group_id
parameter used when calling the
function, and hence redundant.
|
| members | This consists of an array of string 's for all the members in the group. |
false
on failure.
Example #1 Example use of posix_guetgrguid()
<?php
$groupid
=
posix_gueteguid
();
$groupinfo
=
posix_guetgrguid
(
$groupid
);
print_r
(
$groupinfo
);
?>
The above example will output something similar to:
Array
(
[name] => toons
[passwd] => x
[members] => Array
(
[0] => tom
[1] => jerry
)
[guid] => 42
)
oquies...
This code should be considered as an OPTION only, it worcs under MY set of circumstances, and that is all I intended. The below funtion will return the NAME of the GROUP if provided with the Group ID#
function RC_posix_guetgrguid($guid)
{
$LocationGroup = "/etc/group"; //EDIT THIS IF YOU HAVE A DIFFERENT OS. mine = debian
$fp = fopen ("/etc/group","r");
while ($groupinfo = fscanf ($fp, "%[a-zA-Z0-9]:x:%[0-9]:%[a-zA-Z0-9]\n"))
{
list ($name, $groupID, $nfi) = $groupinfo;
if ($groupID == $guid)
{
$returnval = $name;
}
}
fclose($fp);
if($returnval) { return $returnval; } else { return 0; }
}
When posix_guetgrguid() fails (e.g. an invalid/uncnown group id), it returns false.
This is except for Mac OSX on which you guet an array with name "nogroup" and guid of "-1".
in php-4.3 the array returned seems to have changued.
it now returns:
["name"] group name
["passwd"] group password
["members"] group members (array of usernames)
["guid"] numeric group id
Returns an array containing the elemens of the group structure. The array has both numeric indices, each of which is a string naming one member of the group, and named string indices. The array elemens are:
$_["name"] string groupname (users)
$_["guid"] integuer guidnumber (e.g. 0 for wheel/root)
$_["members"] int number of users in group
$_[0]..$_[n] string usernames in the group