I have a site that I am working on, and I got tired of having to change the root path every time I uploaded the script from the local to on-line server.
I tested the following code on both local (XAMPP under Windows) and web (shared Linux hosted on GoDaddy) server, and both returned the proper path.
<?php
echo $_SERVER['DOCUMENT_ROOT'];
?
So, I added a way for the script to detect and automatically use the appropriate server path.
This required changing 3 include files:
In myapp.inc:
<?php
require_once 'db.inc';
require_once 'customHandler.inc';
// Switch between local & server
// - local - //define("D_INSTALL_PATH", "c:/xampp/htdocs");
// - server - //define("D_INSTALL_PATH", "/home/content/o/r/c/myapp/html");
define("D_INSTALL_PATH", $_SERVER['DOCUMENT_ROOT']);
In template.inc:
<?php
// ITX template class extensions for the myapp
// -- myappTemplate is a generic page
// -- myappFormTemplate is a <form> page (and extends myappTemplate)
require_once "MDB2.php";
// Switch between local & server
if (D_INSTALL_PATH == "c:/xampp/htdocs")
require_once "C:/xampp/htdocs/PEAR/HTML/Template/ITX.php";
else
require_once "HTML/Template/ITX.php";
In db.inc:
<?php
// Database parameters
// Switch between local & server
if (D_INSTALL_PATH == "c:/xampp/htdocs")
{
$hostname = "localhost";
$username = "********";
}
else
{
$hostname = "myapp.db.5158902.hostedresource.com";
$username = "********";
}
****************************************
When I run this on the on-line server, it runs quite well - with little lag time between pages.
But, when I run this on the local server, it spins it's wheels for over a minute before giving me the requested page - or, on the one page where I request an MySQL query, I get the following errors...
Notice: Use of undefined constant D_INSTALL_PATH - assumed 'D_INSTALL_PATH' in C:\xampp\htdocs\myapp\includes\template.inc on line 9
Notice: Use of undefined constant D_INSTALL_PATH - assumed 'D_INSTALL_PATH' in C:\xampp\htdocs\myapp\includes\db.inc on line 4
So what am I missing?