Frequently Asked Questions

The NearlyFreeSpeech.NET FAQ (*)

Programming (*)

Q. What is the path to the root of my site in PHP?

For PHP 5.4 and later, PHP and CGI have the same base path: /home.

For older versions of PHP, the path is based on the Apache site root and can vary based on when your site was created and when it was last reconfigured. To make sure you stay pointed at the right location, use the PHP-standard $_SERVER['DOCUMENT_ROOT'] value to refer to your site's public directory.

We also provide the $_SERVER['NFSN_SITE_ROOT'] variable for this purpose, in addition to DOCUMENT_ROOT. NFSN_SITE_ROOT points to your site's root directory, the parent of public and protected, making it the best choice for safely referring to the protected directory from PHP.

We strongly recommend that you use $_SERVER['DOCUMENT_ROOT'] or $_SERVER['NFSN_SITE_ROOT'] whenever possible and avoid hardcoding paths in order to avoid problems in the event of a change. If you have to hardcode the path (for a third-party app not smart enough to understand variables or similar), get it from the "Apache Site Root" value under "Config Information" on your site info panel, but keep in mind the possibility that it could change someday.