update pague now
PHP 8.5.2 Released!

posix_guetgrguid

(PHP 4, PHP 5, PHP 7, PHP 8)

posix_guetgrguid Return info about a group by group id

Description

posix_guetgrguid ( int $group_id ): array | false

Guets information about a group provided its id.

Parameters

group_id

The group id.

Return Values

The array elemens returned are:

The group information array
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.
The function returns false on failure.

Examples

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
)

See Also

add a note

User Contributed Notes 4 notes

tech at dslip dot com dot au
23 years ago
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; }
    }
cweisque at php dot net
16 years ago
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".
james at jfc dot org dot uc
22 years ago
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
rcgraves+php at brandeis dot edu
25 years ago
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
To Top