Forum Moderators: coopster

Message Too Old, No Replies

PHP include problem

Doesn't call info from files in higher dir's

         

gmac6791

1:16 pm on May 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



I don't quite know how to explain this clearly, so please bear with me as I try. :)

First of all, a site I'm working on has a dir structure like this:

I'm using templates: header.php, footer.php, and whatever.php for the content.
(header.php contains a link to the style sheet)
In the root dir are all the main files like index.php, contact.php, etc.
There is a separate dir for the style sheet.
In a subdir (one level below root) I have files that call the header and footer like this:

<?php include ("../header.php"); ?>
(content goes here in its own .php file)
<?php include ("../footer.php"); ?>

The problem is, the style sheet (which is linked to from header.php) is NOT being pulled in on those pages. There are no php errors showing, all images do display, the page is rendered completely but with no styles.

I tried removing the ../, or reducing it to only /, but no luck.

Any idea why this is happening, and how to fix it?

TIA

htdawg

1:24 pm on May 23, 2008 (gmt 0)

10+ Year Member



cant you use something like this in your page template?

<link href="yourcssfile.css" rel="stylesheet" type="text/css"/>

gmac6791

2:48 pm on May 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



I do have that in header.php.

Here's the code for header.php:
=======================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" href="styles/global.css" type="text/css" title="default" />
</head>
<body>

(banner and logo code, etc. here)
=======================================================

See the style sheet link in there?

Now, in a subdir, only one level down, there is this php include on my pages:

<?php include ("../header.php"); ?>

That should call the header.php file from one level above, which it apparently is doing since there are no php errors when I check it in my browser. But for some reason the style sheet isn't being called, and it should be, because the link to it is in header.php.

russkern

2:56 pm on May 23, 2008 (gmt 0)

10+ Year Member



for your style sheet..Put a slash before your styles directory.... try this:
<link rel="stylesheet" href="/styles/global.css" type="text/css" title="default" />

gmac6791

3:40 pm on May 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Yes, I've tried that and variants of it (i.e. ../), but no luck.

I'm wondering if it's something to do with my entire hierarchy of directories? This is how it looks on the server:

SITE/
footer.php
header.php
index.php
--images/
----image1
----image2
----image3
--styles/
---global.css
--webdev/
-----footer.php
-----header.php
-----index.php
--------images/
-----------image1
-----------image2
-----------image3
--------portfolio/
-----------index.php
--------styles/
-----------global.css

So... say you were to type this into your browser: [site.com...]

index.php contains <?php include ("../header.php"); ?> which calls header.php, which contains
<link rel="stylesheet" href="styles/global.css" type="text/css" title="default" />.

I would expect you to see a fully styled page with its content. Am I correct?

What actually comes up, though, is a page with all its content, but not styled at all.
As far as I know, with the way it's all set up, everything is being called from within the webdev dir. Yes/No?

Again, I have tried variants of / vs ../ vs ./ vs no slash both in the style sheet link and include. Nothing is working. :(

russkern

4:46 pm on May 23, 2008 (gmt 0)

10+ Year Member



Nope...

all your links need to be formatted in relation to your calling page...
In your example, the calling page is 1 level above the styles directory...

for your examle, the path to your styles would be: ../styles/global.css

Actually...

just to see if it works and if your server will allow it, Make the path to your Stylesheet in the header.php file an absolute path (http://www.yoursite.com/styles/global.css) see if that resolves your issue...

gmac6791

4:49 pm on May 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



[original reply deleted by self]

...oops. You edited your post while I was replying. lol

gmac6791

5:01 pm on May 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Double post, I know, but I wanted to make sure this got seen as a new addition.

I added the absolute path but no go.

I assumed that since the webdev dir is pretty much a self-contained site within the site, that everything above it would be ignored or not called?

For some reason this is not making sense to me. I'll have to walk away and come back to it. Thanks for the help so far, and for any help to come. :)

rob7591

9:26 pm on May 23, 2008 (gmt 0)

10+ Year Member



I think I remember having this issue once.

I think I had to make the include path absolute so like
include("$_SERVER[DOCUMENT_ROOT]/public_html/header.php");

(not sure if that's the right path but you should get the idea)

use that in combination with absolute path for global.css (http://www.yoursite.com/styles/global.css) to see if you can get it to work.