Open In App

PHP posix_getpwuid() Function

The posix_getpwuid() function is an inbuilt function in PHP that returns data related to a user using its user-id. This function returns an array with user information.

Syntax:



posix_getpwuid(int $user_id): array|false

Parameter: This function accepts a single parameter:

Return Value: This function returns an associative array with some elements. Elements of the associative array are name, password, uid, gid, geckos, dir, and shell. If it will fail it returns “false”.



Example 1: The following code demonstrates the posix_getpwuid() function.




<?php
  
$userinfo = posix_getpwuid(1000);
  
print_r($userinfo);
  
?>

Output:

Array
(
    [name] => dachman
    [passwd] => x
    [uid] => 1000
    [gid] => 1000
    [gecos] => dachman,,,
    [dir] => /home/dachman
     => /usr/bin/zsh
)
   

Note: Output will be different according to your system.

Example 2: The following code demonstrates the posix_getpwuid() function.




<?php
  
$userinfo = posix_getpwuid(10000);
  
if ($userinfo) {
    echo "User is available";
} else {
    echo "User is not available";
}
  
?>

Output:

User is not available 

Reference: https://www.php.net/manual/en/function.posix-getpwuid.php

Article Tags :