Absolute Includes
Posted: Mon Feb 27, 2006 4:06 pm
Hi All,
PHP newb here. I'm creating a website and I'd like to include my css stylesheets on each page using a php include. My site has many page at diferent folder depths, which can be a problem. After some research, I learned that I can include the php file from any folder depth by using the following syntax:
This enabled me to get to the include I want from all of my pages, BUT the paths within the includes would be broken. Here's my stylesheet include:
Obviously, if this file is included anywhere but in the root, the paths to the css files will be wrong. So I tried this:
...and that's where I'm stuck. When I refresh the page after having made that change, the styles aren't applied to the page. BUT, when I look at the source code, the href path points to the proper place in my local file structure. (i'm developing this locally)
So what am I missing? While putting $_SERVER["DOCUMENT_ROOT"] into my path to my css file might work, it seems like a really inefficient way to handle includes. Is there a better way?
Thanks in advance,
jeff
PHP newb here. I'm creating a website and I'd like to include my css stylesheets on each page using a php include. My site has many page at diferent folder depths, which can be a problem. After some research, I learned that I can include the php file from any folder depth by using the following syntax:
Code: Select all
<?php include($_SERVER["DOCUMENT_ROOT"].'/_includes/components/stylesheets.php'); ?>Code: Select all
<link rel="stylesheet" type="text/css" href="_includes/css/main.css" />
<link rel="stylesheet" type="text/css" href="_includes/css/navigation.css" />Code: Select all
<link rel="stylesheet" type="text/css" href="<?php echo $_SERVER["DOCUMENT_ROOT"] ?>/_includes/css/main.css" />
<link rel="stylesheet" type="text/css" href="_includes/css/navigation.css" />So what am I missing? While putting $_SERVER["DOCUMENT_ROOT"] into my path to my css file might work, it seems like a really inefficient way to handle includes. Is there a better way?
Thanks in advance,
jeff