viperjts10 Posted July 13, 2010 Share Posted July 13, 2010 So, if I have my main site in the root directory (public_html), and then I have my admin section in (public_html/admin). Is there a special way to go about using the included files on both my admin area and the homepage area, such as the style sheets, headers, footer etc.. I have my header, footer, and stylesheet included on my main index page using the regular php include function. However, if I use that SAME include function on my admin page, I have to use the double dot notation to go down a directory in order to find the correct file... require_once('../includes/header.php'); This works in that the header is included, however, my stylesheet doesn't load because in my header, I have the location for the stylesheet as <link href="styles/global.css" rel="stylesheet" type="text/css" /> -> Thus it's looking in the same directory to find the "styles" folder. How would I go about including the same stylesheet that the root directory is using while still using the header page on both my homepage and in the admin area. I want to do this without needing to alter anything in the included files for my website. If this makes sense, hopefully someone can help me, if not I'll try and explain better what I'm trying to accomplish. Link to comment https://forums.phpfreaks.com/topic/207650-using-includes-within-different-directories/ Share on other sites More sharing options...
khr2003 Posted July 14, 2010 Share Posted July 14, 2010 try to use the base tag Link to comment https://forums.phpfreaks.com/topic/207650-using-includes-within-different-directories/#findComment-1085650 Share on other sites More sharing options...
Pikachu2000 Posted July 14, 2010 Share Posted July 14, 2010 The <base> tag is used within html, not PHP. include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php'); Link to comment https://forums.phpfreaks.com/topic/207650-using-includes-within-different-directories/#findComment-1085658 Share on other sites More sharing options...
khr2003 Posted July 14, 2010 Share Posted July 14, 2010 The <base> tag is used within html, not PHP. that is my intention exactly. I think viperjts10 does not have any problem including the php file, it is the html inside it (and more specifically the style sheet) that needs to be included properly, thus the base tag. Link to comment https://forums.phpfreaks.com/topic/207650-using-includes-within-different-directories/#findComment-1085661 Share on other sites More sharing options...
Pikachu2000 Posted July 14, 2010 Share Posted July 14, 2010 I thought at first you were addressing the first part of the post. I see where you're going with that, but I think using a <base> tag would present the issue of inflexibility to move between servers, and would be a hassle during development. Although I could be wrong, I think this would be a better solution. <link href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/styles/global.css" rel="stylesheet" type="text/css" /> Link to comment https://forums.phpfreaks.com/topic/207650-using-includes-within-different-directories/#findComment-1085672 Share on other sites More sharing options...
viperjts10 Posted July 14, 2010 Author Share Posted July 14, 2010 I thought at first you were addressing the first part of the post. I see where you're going with that, but I think using a <base> tag would present the issue of inflexibility to move between servers, and would be a hassle during development. Although I could be wrong, I think this would be a better solution. <link href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/styles/global.css" rel="stylesheet" type="text/css" /> Thank you very much. I don't know how I can forget about these easy things. I have all these global constants defined in one of my files as it is now, and I seem to always forget about using them. Well, this is why I'm practicing now because I'll learn from trial and error. I appreciate the help! TY Link to comment https://forums.phpfreaks.com/topic/207650-using-includes-within-different-directories/#findComment-1085706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.