Search code examples
phpserverphp-7

What is the PHP7 version of $_SERVER['HOME']


Recently, I have installed a new Ubuntu server which incorporates PHP7. Previously, on PHP5.3 (or it may have been a later version of PHP5, I could use $_SERVER['HOME'] which returned the home path of the server (i.e. /var/www/). However, this is not possible in PHP7 as $_SERVER['HOME'] is no more.

If I have a site which has a document root of /var/www//httpdocs, how do I get the /var/www/ part. I can not hard code it as my test server (a Synology NAS) does not use PHP7 and can not be upgraded to PHP7 and thus, I need to use a variable that is constant for PHP5 and PHP7 which return the same result to forumate the same result as $_SERVER['HOME'] did in PHP5.

I tried using $_ENV['HOME'] but this appears to print nothing from my system when a simple die($_ENV['HOME']); is executed.

Can someone put me out of my misery please?

Thanks


Solution

  • OK, thanks to @apokryfos, I have sorted the issue. I perhaps should have mention I wanted to include a file outside of the document root (oops, my bad).

    The getenv('HOME') for some unknown reason returns an empty string on my server, but the method I used to overcome this was to use the dirname option.

    The final result was:

    set_include_path(get_include_path().PATH_SEPARATOR.dirname($_SERVER['DOCUMENT_ROOT'],1)."/includes");
    

    Thanks again for your assistance.