2009-11-01 32 views

回答

1

这是我做的:

class goDirAlias 
{ 
    private function home_dir() 
    { 
     // Try to find out the home directory of the user running this script 
     if(function_exists("posix_getpwnam")) 
     { 
      // using posix 
      $user_info = posix_getpwnam(goDirAlias::whoami()); 
      $home_dir = $user_info['dir']."/"; 
     } else 
     { 
      // Looking for Windows environment variables 
      $home_dir = getenv('HOMEDRIVE').getenv('HOMEPATH').'\\'; 
      if($home_dir == "\\") 
      { 
       // Looking for *nix environment variables 
       $home_dir = getenv('HOME')."/"; 
      } 
     } 

    return $home_dir; 
    } 

    private function whoami() 
    { 
     // Try to find out the username of the user running the script 
     if(function_exists('posix_getpwuid')) 
     { 
      // using posix 
      $user_info = posix_getpwuid(posix_geteuid()); 
      $running_user = $user_info['name']; 
     } else { 
      // Looking for Windows environment variables 
      $running_user = getenv('USERNAME'); 
      if(empty($running_user)) 
      { 
       // Running *nix whoami 
       $running_user = exec('whoami'); 
      } 
     } 

    return $running_user; 
    } 
} 
+0

这就是我正在寻找!谢谢塞巴斯蒂安。 – Castro 2010-04-28 21:17:53

-1

你可以在Linux上试试这个。

function get_home_user($username) 
{ 
$username=$_POST["username"]; 
if (!empty($username))     
{ if(exec ("test (home/$username)")) 
    return true; 
} 
return false; 
} 
+0

返回true或false,并且还覆盖参数$用户名与岗位价值。看起来很糟糕。 无论如何,谢谢! – Castro 2009-11-01 20:47:05

+0

我不好意思,它应该返回真或假那就OK – streetparade 2009-11-01 20:59:15

相关问题