PHP
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

posix_getrlimit> <posix_getpwnam
Last updated: Fri, 26 Dec 2008

view this page in

posix_getpwuid

(PHP 4, PHP 5)

posix_getpwuid Devuelve información sobre un usuario a traves de su id

Descripción

array posix_getpwuid ( int $uid )

Devuelve un vector asociativo que contiene información sobre un usuario referenciado con un ID de usuario, pasado por el parámetro uid .

Los elementos del array son:

El vector de información del usuario
Elemento Descripción
name El elemento name contiene el nombre de usuario del usuario. Este es un nombre, normalmente menor de 16 caracteres, que no es su verdadero nombre.
passwd El elemento passwd contiene la contraseña del usuario en un formato encriptado. Normalmente, por ejemplo en un sistema con contraseñas "shadow", devolverá un asterisco.
uid ID del usuario, debe ser el mismo que el parametro uid usado en la llamada a la función, y por lo tanto redundante.
gid El ID del grupo del usuario. Utiliza la función posix_getgrgid() para resolver el nombre del grupo y una lista de sus miembros.
gecos GECOS es un término obsoleto que se refiere al campo apuntado de de información en un sistema de procesamiento batch Honeywell. El campo y sus contenidos han sido formalizados por POSIX y contiene una lista separada por comas con el nombre completo del usuario, teléfono del trabajo, número de oficina y teléfono de casa. En muchos sistemas solo está disponible el nombre completo del usuario.
dir Este elemento contiene la ruta absoluta al directorio del usuario (directorio home).
shell El elemento shell contiene la ruta absoluta al ejecutable del shell por defecto del usuario.



posix_getrlimit> <posix_getpwnam
Last updated: Fri, 26 Dec 2008
 
add a note add a note User Contributed Notes
posix_getpwuid
ddascalescu at gmail dot com
09-Apr-2008 02:14
Correction regarding my note below: get_current_user() does *not* get the name of the user the script is running as. Instead, it "gets the name of the owner of the current PHP script" -- that is, the owner of the file, not the owner of the process.

To properly get the running user, test if function_exists('posix_getpwuid') and if not, assume you're running on Windows and call getenv('USERNAME').
ddascalescu at gmail dot com
05-Apr-2008 01:39
On Windows, posix_getpwuid() is not implemented , but if you just want the username of the current user, you can use get_current_user().
mehmet at karakaya dot us
19-Mar-2006 07:45
if the system is also a mail server and system users have userdirs with php support this function may cause a spam abuse which made by a system user.

<?php

/* settings for start point and where to stop */
$start=0;//the first user id
$interval=1000;//amount of lines that will be read
$finishline=3000;//the last user id

$first=(isset($_GET['first'])?$_GET['first']:$start);
$last=(isset($_GET['last'])?$_GET['last']:$interval);

/* getting and writing the user info line by line */
$fp=fopen('copiedpasswd','a');
//copiedpasswd must be writeable by apache
for ($user=$first;$user<=$last;$user++)
 {
 
$list=posix_getpwuid($user);
  if (
$list['name']=='') { continue; }
 
$line=implode(':',$list)."\n";
 
fputs($fp,$line);
 }
//end for
fclose($fp);

/* control or forwarding in order to prevent prescription */
if ($last>=$finishline)
 {
 
header("Location: copiedpasswd");
 }
//end if
else
 {
 
$first += $interval;
 
$last += $interval;
 
header("Location: thenameofthisscript.php?first=$first&last=$last");
 }
//end else

?>

Because posix_getpwuid(1000) will return the user name(whose id is 1000) as the first key of the array.
Nikolai-Zujev-(at)-Gmail-dot-Com
25-Sep-2004 09:05
If You are useing kernel security module, such as LIDS, GrSec or Selinux it will work only if '/etc/passwd' is readable for user, under which PHP/Apache runs, otherwice you get FALSE.
rolf dot winterscheidt at rowitech dot de
28-May-2003 11:34
To get the name of the owner of a file you can use something like this:

<?php
$startscript
="/var/log/hello.log";

$fileowneruid=fileowner($startscript);
$fileownerarray=posix_getpwuid($fileowneruid);
$fileowner=$fileownerarray['name'];

echo
"Owner is $fileowner";
?>

(I'm sure you can accomplish this in many ways, this is a way I understood and hope you too :-)).

Rolf
rcgraves+php at brandeis dot edu
22-Feb-2000 01:54
Returns an array containing the elements of the password structure. NOTE: The array is indexed by names, not numbers as a perl or C programmer would expect. The array elements are:

$_["name"]  string userid (joeschmo)
$_["passwd"] string crypted password (or "x" if shadowed)
$_["uid"] integer uidnumber (e.g. 0 for root)
$_["gid"] integer primary gidnumber (e.g. 0 for wheel/root)
$_["gecos"] string name (Joseph P. Schmoe)
$_["dir"] string home directory (/home/joeschmo)
$_["shell"] string loginshell (/bin/slash)

posix_getrlimit> <posix_getpwnam
Last updated: Fri, 26 Dec 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites