Hi everyone, When I was building my site locally, I was using the following code to ensure all my links resolved: <?php if(!defined('__ROOT__')){ if ($_SERVER['HTTP_HOST'] != "mysite.com") { define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/mysite'); } else { define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']); } } ?> PHP: Then I'd used this to include some code: <?php include_once(__ROOT__ . "/includes/config.inc.php"); include_once(__ROOT__ . "/includes/helpers.inc.php"); ?> PHP: I thought that once I deployed my site on the remote server that I wouldn't need to change any code, ie. that the constant definition above would ensure everything worked. However when I uploaded the site, I found that I needed to swap out the above mentioned constant with the following line so that all the links worked correctly: <?php define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']); ?> PHP: Can anyone tell me why it didn't work or what I can do next time to ensure that it does? Appreciate any advice.
In the address bar, do you have mysite.com or www.mysite.com. If it's the latter, then it will still think it's not your website
I use if(strstr($_SERVER['SERVER_NAME'], "devserver.com")) { } elseif(strstr($_SERVER['SERVER_NAME'], "liveserver.com")) { } Code (markup):
Personally I would just use a switch switch ($_SERVER['SERVER_NAME']) { case 'mysite.com': case 'www.mysite.com': define('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/mysite'); break; case 'localhost': define('__ROOT__', $_SERVER['DOCUMENT_ROOT']); break; } PHP:
Thanks for the replies, I tried the above code but when I put the page on the remote server I got the following error: Parse error: syntax error, unexpected T_STRING, expecting T_CASE or T_DEFAULT or '}' in /home/mysite/www/www/business/index.php on line 3 Line 3 is as follows: Â Â case 'mysite.com': Obviously I replaced the domain names with the correct ones but I still don't know why it's not working. It was only when I replaced the code with the following did it work: define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']); Does anyone have any suggestions?
Read wordpress sources and learn how to make your code flexible and independent on the directory you put it. It seems your hosting provider has no subdirectories for virtual hosts or substituted DOCUMENT_ROOT straight to your vhost dir. do echo $_SERVER['DOCUMENT_ROOT'] and see what it is.
I inserted the echo statement that you suggested but nothing was printed. It just continued to give me the same error. I'm not sure how to solve it. Any other further advice appreciated.
The error I'm getting now is the following: Warning: include_once(/home/mysite/www/www/mysite_2010/includes/config.inc.php) [function.include-once]: failed to open stream: No such file or directory in /home/mysite/www/www/business/index.php on line 12 Line 12 is: include_once(__ROOT__ . "/includes/config.inc.php"); Does the above line need to be different now that the constant code has been changed?