posix_seteuid

(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)

posix_seteuid現在のプロセスの実効 UID を設定する

説明

posix_seteuid(int $user_id): bool

現在のプロセスの実効ユーザー ID を設定します。 この関数は特権関数であり、実行するにはシステム上において適当な権限 (通常は root) が必要です。

パラメータ

user_id

ユーザー ID。

戻り値

成功した場合に true を、失敗した場合に false を返します。

参考

  • posix_geteuid() - 現在のプロセスの有効なユーザー ID を返す
  • posix_setgid() - 現在のプロセスの GID を設定する
  • posix_getuid() - 現在のプロセスの実際のユーザー ID を返す

add a note

User Contributed Notes 1 note

up
1
divinity76 at gmail dot com
5 years ago
if you want to set uid by username rather than uid, try combining it with posix_getpwnam(),<?phpposix_seteuid (posix_getpwnam("www-data")["uid"]);posix_setegid(posix_getpwnam("www-data")["gid"]);?>note that posix_getpwnam() reads /etc/passwd on each invocation, if you need it to go fast, this should be faster (only read passwd once):<?php$posix_user_info=posix_getpwnam("www-data");posix_seteuid ($posix_user_info["uid"]);posix_setegid($posix_user_info["gid"]);?>and to go back to being root, just set them to 0,<?phpposix_seteuid(0);posix_setegid(0);?>
To Top