DataDev DataDev - 2 months ago 8
PHP Question

Defined url function failure

I have a my db connect is included in my header on localhost

when i echo out

<?php echo $_SERVER['DOCUMENT_ROOT'];?>



Results C:/Program Files (x86)/Zend/Apache24/htdocs


when the path should be


C:/Program Files (x86)/Zend/Apache24/htdocs/mycms


if i use the following

<?php include($_SERVER['DOCUMENT_ROOT'] . '/mycms/modules/int.php');?>


it works but, but is there any way to get the path of the folder its in without adding it hard coded?

I have also tried this

<?php include($_SERVER['SERVER_NAME']. dirname($_SERVER['PHP_SELF'] . '/modules/int.php'));?>

Answer

Supposedly you want something like this:

<?php
    // ASSUMING THE CURRENT FILE IS IN THE DIRECTORY: "mycms"
    defined('SITE_ROOT') or define('SITE_ROOT', __DIR__);
    defined('ROOT_URI')  or define('ROOT_URI', 'http://localhost/mycms');

    include(SITE_ROOT . '/modules/int.php');

    // AND NOT
    include(ROOT_URI . '/modules/int.php');