I can think of one reason. From your snippet posted on Stack Overflow, I noticed the top lines.
$DIR = explode("public_html", __DIR__);
$urlLOC = str_replace("engine","",$DIR);
This is using the text 'public_html' as the delimiter for the PHP 'explode' function. This strategy will not work if your document root is not named 'public_html.'