futrose Posted February 24, 2011 Share Posted February 24, 2011 I have been trying to learn how to build a php/mysql website using my local computer for testing. I'm at the point now where I need to move my files over to our server so I can give an update and show how much I have done. On my computer I have been setting up my include lines like this. include $_SERVER['DOCUMENT_ROOT'] . '/includes/head.inc.php'; the problem is that when I move my files over to the server I want to put them in a .htpassword protected directory called dbsite until the new site is ready to go live at which point I will move the files out of that directory and put them in the root dir. (there is currently I live site which I am replacing with this new one in the root right now, but until I'm ready I can't delete/overwrite the current one) My question is, is there a way to make $_SERVER['DOCUMENT_ROOT'] = the dbsite dir instead of the actual root dir? Just temporarily while the site is in the testing directory on the server. Otherwise I have to change all of my lines on my local computer from include $_SERVER['DOCUMENT_ROOT'] . '/includes/head.inc.php'; to include $_SERVER['DOCUMENT_ROOT'] . '/dbsite/includes/head.inc.php'; which will then cause the files on my local computer to not work correctly. Am I making sense as to my dilemma? Is there an easier/better solution? Thanks. Quote Link to comment Share on other sites More sharing options...
samoht Posted February 24, 2011 Share Posted February 24, 2011 I would think about defining your own base url variable and use that instead of SEVER['document_root']. define('BASE', 'path/to/your/base/url'); then your code would look like: include BASE . '/includes/head.inc.php'; Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted February 24, 2011 Share Posted February 24, 2011 Includes are relative to the PHP file that is first called in the browser. So assuming you have an index.php file or something in the document root that is the first file loaded, then all includes will be relative to /docroot. If the file is in /docroot/dbsite then this should work for both cases: include 'includes/head.inc.php'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.