PHP detect if in subdirectory

Use dirname($_SERVER['SCRIPT_NAME']) to get the directory portion of the URI.


Your syntax error is because you are missing the ; at the end of $scriptname="install.php".

Your method looks like it should work okay.

Another way you could determine if the file is installed at the domain root instead of a folder or subdomain would be something like this:

function subdomboolcheck()
{
    $root = $_SERVER['DOCUMENT_ROOT'];
    $filePath = dirname(__FILE__);

    if ($root == $filePath) {
        return false; // installed in the root
    } else {
        return true;  // installed in a subfolder or subdomain
    }
}

Tags:

Php