Skip to content

Instantly share code, notes, and snippets.

@derky1202
Created September 8, 2013 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derky1202/6482445 to your computer and use it in GitHub Desktop.
Save derky1202/6482445 to your computer and use it in GitHub Desktop.
<?php
if(function_exists('posix_geteuid')){
// use posix to get current uid and gid
$uid = posix_geteuid();
$usr = posix_getpwuid($uid);
$user = $usr['name'];
$gid = posix_getegid();
$grp = posix_getgrgid($gid);
$group = $grp['name'];
}else{
// try to create a file and read it's ids
$tmp = tempnam ('/tmp', 'check');
$uid = fileowner($tmp);
$gid = filegroup($tmp);
// try to run ls on it
$out = `ls -l $tmp`;
$lst = explode(' ',$out);
$user = $lst[2];
$group = $lst[3];
unlink($tmp);
}
echo "Your PHP process seems to run with the UID $uid ($user) and the GID $gid ($group)\n"; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment