mrbuter Posted March 7, 2008 Share Posted March 7, 2008 Alright I thought this would be easier but I can't seem to find it through google :\ I have an includes folder with a config.php and connection.php for mysql. Anything in the root directory can include that fine (include("/includes/connection.php") and anything in the includes folder can as well (include("connection.php") However, I don't know how to get anything in a DIFFERENT folder to include something in the includes folder. for example, www.mysite.com/folder1/index.php can't include www.mysite.com/includes/connection.php. I could do include("http://www.mysite.com/includes/connection.php"); but I am making something which I am going to give to a couple of friends so having them edit a bunch of files to reflect their own url would be silly. There _HAS_ to be a way to make php jump to the root public html directory isn't there? I was looking at some vbulletin code and they do this by doing stuff like require_once(DIR . '/includes/functions_databuild.php'); but how do they define DIR? Quote Link to comment Share on other sites More sharing options...
cry of war Posted March 7, 2008 Share Posted March 7, 2008 www.mysite.com/folder1/index.php can't include www.mysite.com/includes/connection.php. if your trying to go up a folder try this in www.mysite.com/folder1/index.php include www.mysite.com/../includes/connection.php. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2008 Share Posted March 7, 2008 The DIR is a defined constant that the code or a configuration file sets up. However, I recommend using $_SERVER['DOCUMENT_ROOT'] for all include/require files so that you can reuse code in different paths and never have to worry about being able to get a relative path to work. The following will work (assuming the includes/connection.php is correct) no matter what file contains the include() statement - include($_SERVER['DOCUMENT_ROOT'] . "/includes/connection.php"); Including a file using a URL (http:/www.yourdomain.com) will only include content that is output to the browser and does not actually include php code/data. 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.