Jump to content

using 'includes' within different directories


viperjts10

Recommended Posts

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.

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.

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" />

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.