From the command line, I can get the home directory like this:
~/
How can I get the home directory inside my PHP CLI script?
#!/usr/bin/php
<?php
echo realpath(~/);
?>
From the command line, I can get the home directory like this:
~/
How can I get the home directory inside my PHP CLI script?
#!/usr/bin/php
<?php
echo realpath(~/);
?>
Use $_SERVER['HOME']
Edit:
To make it complete, see what print_r($_SERVER)
gave me, executed from the command line:
Array
(
[TERM_PROGRAM] => Apple_Terminal
[TERM] => xterm-color
[SHELL] => /bin/bash
[TMPDIR] => /var/folders/Lb/LbowO2ALEX4JTK2MXxLGd++++TI/-Tmp-/
[TERM_PROGRAM_VERSION] => 272
[USER] => felix
[COMMAND_MODE] => unix2003
[__CF_USER_TEXT_ENCODING] => 0x1F5:0:0
[PATH] =>/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin
[PWD] => /Users/felix/Desktop
[LANG] => de_DE.UTF-8
[SHLVL] => 1
[HOME] => /Users/felix
[LOGNAME] => felix
[DISPLAY] => /tmp/launch-XIM6c8/:0
[_] => ./test_php2
[OLDPWD] => /Users/felix
[PHP_SELF] => ./test_php2
[SCRIPT_NAME] => ./test_php2
[SCRIPT_FILENAME] => ./test_php2
[PATH_TRANSLATED] => ./test_php2
[DOCUMENT_ROOT] =>
[REQUEST_TIME] => 1260658268
[argv] => Array
(
[0] => ./test_php2
)
[argc] => 1
)
I hope I don't expose relevant security information ;)