posix_geteuid

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

posix_geteuidReturn the effective user ID of the current process

说明

posix_geteuid(): int

Return the numeric effective user ID of the current process. See also posix_getpwuid() for information on how to convert this into a useable username.

参数

此函数没有参数。

返回值

Returns the user id, as an int

示例

示例 #1 posix_geteuid() example

This example will show the current user id then set the effective user id to a separate id using posix_seteuid(), then show the difference between the real id and the effective id.

<?php
echo posix_getuid()."\n"; //10001
echo posix_geteuid()."\n"; //10001
posix_seteuid(10000);
echo
posix_getuid()."\n"; //10001
echo posix_geteuid()."\n"; //10000
?>

参见

添加备注

用户贡献的备注 2 notes

up
2
divinity76+spam at gmail dot com
2 years ago
if you for some reason need the euid without depending on php-posix being available, try

<?php
function geteuid_without_posix_dependency(): int
{
try {
// this is faster if available
return \posix_geteuid();
} catch (
\Throwable $ex) {
// php-posix not available.. fallback to hack
$t = tmpfile();
$ret = fstat($t)["uid"];
fclose($t);
return
$ret;
}
}
up
0
Anonymous
3 months ago
Please note the example code shown above is invalid and will fail, since UID 10001 cannot use posix_seteuid to change its UID to 10000
To Top