Getting to common script from multiple entry points
<p>I have multiple sub-sites and each has it's own entry as well as an administrator entry point.  I didn't show it, but each subdomain and subdomain/admin directory also contains a library directory which is a soft symbolic link to a common directory.  Note that the administrator directory can have different names (i.e. administrator, admin, myadmin).</p>

<pre><code>var/www/html/subdomain1/index.php
var/www/html/subdomain1/administrator/index.php
var/www/html/subdomain2/index.php
var/www/html/subdomain2/admin/index.php
var/www/html/subdomain3/index.php
var/www/html/subdomain3/myadmin/index.php
</code></pre>

<p>If either index.php or admin/index.php is accessed, I execute the same script, but need to know which once was accessed.  Also, I need to know whether subdomain1, 2, or 3 was accessed.  Lastly, I need it to work whether access by <a href="http://mainsite.com/subdomain1" rel="nofollow">http://mainsite.com/subdomain1</a>, <a href="http://mainsite.com/subdomain1/index.php" rel="nofollow">http://mainsite.com/subdomain1/index.php</a>, <a href="http://subdomain1.mainsite.com/index.php" rel="nofollow">http://subdomain1.mainsite.com/index.php</a>, or even a different domain name pointing to /www/html/subdomain1.</p>

<p>So, how do I do this?  I am thinking one option is to make index.php and admin/index.php both symbolic links to a common file which contains:</p>

<pre><code>$document_root_array=explode('/',trim($_SERVER['DOCUMENT_ROOT'],'/'));
$php_self_array=explode('/',trim($_SERVER['PHP_SELF'],'/'));
if(count($document_root_array)==3)
{
    //Subdirectory
    $domain_name=$php_self_array[0];
    //$php_self_array['1'] is either a frontend file or the admin directory.
    if(count(explode('.',$php_self_array[1]))==2)
    {
        //Must be a file.php
        $sitetype='front';
        $file=$php_self_array[1];
    }
    else
    {
        //Must be admin
        $file=($php_self_array[2]=='lib')?$php_self_array[3]:$php_self_array[2];
        $sitetype='back';
    }
}
elseif(count($document_root_array)==4)
{
    //Domain pointing directly to file
    $domain_name=$document_root_array[4];
    //$php_self_array['0'] is either a frontend file or the admin directory.
    if(count(explode('.',$php_self_array[0]))==2)
    {
        //Must be a file.php
        $sitetype='front';
        $file=$php_self_array[0];
    }
    else
    {
        //Must be admin
        $file=($php_self_array[1]=='lib')?$php_self_array[2]:$php_self_array[1];
        $sitetype='back';
    }
}
</code></pre>

<p>Seems to work, however, I am concerned that it might not be secure.</p>

<p>Instead, maybe make both index.php and admin/index.php actual files which first define a constant indicating whether it is front or back, and then require() the common file?</p>

<p>Any thoughts of which solution is best, or if there is a better solution which I didn't even mention?</p>

<p>Thanks</p>
