Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP detect if in subdirectory

Tags:

php

I want to determine if the PHP file I am on install.php is in a subdomain/subdirectory (basically not at domain.com/install.php).

Found solution to my problems

see below

like image 424
Chris Mirno Avatar asked Aug 05 '12 00:08

Chris Mirno


2 Answers

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

like image 151
Barmar Avatar answered Nov 03 '22 16:11

Barmar


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
    }
}
like image 2
drew010 Avatar answered Nov 03 '22 16:11

drew010