lakeccrunner Posted December 10, 2007 Share Posted December 10, 2007 I've been using the php Include function for a while now, but I used to use it for individual pages. Now, I want to have the files in one place, and be able to update them. before I was using the traditional <?php include("include.php") ?> But I can't figure out how to recode it so I can have the include.php in the main directory and nowhere else. Thanks in advance for any help. Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 <?php include $_SERVER['DOCUMENT_ROOT'] . '/include.php'; ?> Quote Link to comment Share on other sites More sharing options...
lakeccrunner Posted December 10, 2007 Author Share Posted December 10, 2007 ^ I haven't defined any variables yet, though... Quote Link to comment Share on other sites More sharing options...
revraz Posted December 10, 2007 Share Posted December 10, 2007 $_SERVER is a Global, you dont' have to define it. Quote Link to comment Share on other sites More sharing options...
lakeccrunner Posted December 10, 2007 Author Share Posted December 10, 2007 Do I have to define the ['DOCUMENT_ROOT'] part, or just put the page location there? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 10, 2007 Share Posted December 10, 2007 If you put it in your main folder (www.mydomain.com), then it will find it using that array. Quote Link to comment Share on other sites More sharing options...
lakeccrunner Posted December 10, 2007 Author Share Posted December 10, 2007 I put that exact code in, but it isn't working. Is it possible it's not working because the file I want to work is in located in a directory such as www.mydomain.com/derector1/directory2/file.php? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 11, 2007 Share Posted December 11, 2007 Post your code. Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 Is it possible it's not working because the file I want to work is in located in a directory such as www.mydomain.com/derector1/directory2/file.php? Yes its possible, in fact likely seeing as your question was.... But I can't figure out how to recode it so I can have the include.php in the main directory and nowhere else. When you said main I assumed root. Quote Link to comment Share on other sites More sharing options...
lakeccrunner Posted December 11, 2007 Author Share Posted December 11, 2007 ^ Ok, I see. Sorry, what I meant was: I want the include.php file in the main directory only so I don't have to put it under any other directories. Can I modify the code given to get the wanted result? Quote Link to comment Share on other sites More sharing options...
lakeccrunner Posted December 14, 2007 Author Share Posted December 14, 2007 Sorry to double post, but does anyone know the code I would need to use? Quote Link to comment Share on other sites More sharing options...
CMC Posted December 14, 2007 Share Posted December 14, 2007 Yeah you just need to specify the correct path to it. <?php include("/home/USERNAME/public_html/PATH-TO-FILE/FILENAME.php");?> where username is the username you use to login to your website account, path to file is the path to the file (/folder/ for example) and filename is the name of the file. Or as thorpe posted, <?php include $_SERVER['DOCUMENT_ROOT'] . '/include.php'; ?> and just modify the path. So if it's in /directory/directory/include.php... <?php include $_SERVER['DOCUMENT_ROOT'] . '/directory/directory/include.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.