Last active
December 15, 2015 04:19
-
-
Save zerolab/5200481 to your computer and use it in GitHub Desktop.
Detect the user's home dir on Linux/Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get the home directory | |
* | |
* @see http://techblog.zabuchy.net/2012/how-to-detect-user-home-directory-php-linux-windows/ | |
*/ | |
function homedir() { | |
// getenv('HOME') isn't set on windows and generates a Notice. | |
$home = getenv('HOME'); | |
if (empty($home)) { | |
if (!empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) { | |
// home on windows | |
$home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH']; | |
} | |
} | |
return empty($home) ? NULL : $home; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment