webdesign questions (CSS and linking to other directories)

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
In the main domain directory, I've got a .CSS file, a header, and a footer. I'm using php. The index page requires the header once, has the information for the index, and then requires the footer once. The .css file is "linked" at the top of the header. The site functions normally and looks perfect.

If I create directory1 under the main domain directory (domain.tld/directory1) and require the header and footer in the index just like I did with the index of the main webserver directory, the .css doesn't load. The links are the wrong color, text is the wrong size, etc.

:confused:

What am I missing? Since I'm calling the header which calls the .css, should I effectively be calling the .css as well?
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
Shoot I just figured this out. In the header, where I'm calling the .css file, I'm calling "mystyle.css" instead of "domain.tld/mystyle.css". If I change the header to call "domain.tld/mystyle.css" then everything loads no matter what directory I'm calling the header from. Neat. I guess without qualifying the location including "domain.tld" the system is looking for "domain.tld/directory1/mystyle.css" isn't it. Sheesh.

Okay, new question.

When I make a new directory, I have to require "../header.php" instead of "header.php" to show that the header is in the parent directory. What syntax can I use to call a file that's always going to be in the top level directory without going "../../../../../../../../header" for a directory that's seven or eight folders deep into the webserver directory? I tried calling "./header.php"" but that didn't work. I thought, for some reason, that "." meant the top level or top parent directory, but I guess I'm wrong.

How can I use the same code to link to a file in the top level webserver directory, no matter what folder I'm in, no matter how deep I go?

Make sense?
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
LOL - oh man I'm retarded. I just answered my own question in the previous post and didn't realize it :laugh:

/me slaps forehead
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
. (single doe) refers to the current working directory
you can try $_SERVER['DOCUMENT_ROOT'] to get the www-root where your header/footer resides.
example use: require_once $_SERVER['DOCUMENT_ROOT'] . '/header.php';


for the CSS, the followings work:
<link type="text/css" href="/mystyle.css" />

<link type="text/css" href="<?php print 'http://' . $_SERVER['SERVER_NAME']; ?>/mystyle.css" />

the second one will automatically convert the 'http://' . $_SERVER['SERVER_NAME'] part to http://www.yourdomain.com , and this can be good in case you change your domain name, or if you decide to use the code in other domains without having to manually change your hardcoded domain.tld
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
Originally posted by: stndn
. (single doe) refers to the current working directory
you can try $_SERVER['DOCUMENT_ROOT'] to get the www-root where your header/footer resides.
example use: require_once $_SERVER['DOCUMENT_ROOT'] . '/header.php';


for the CSS, the followings work:
<link type="text/css" href="/mystyle.css" />

<link type="text/css" href="<?php print 'http://' . $_SERVER['SERVER_NAME']; ?>/mystyle.css" />

the second one will automatically convert the 'http://' . $_SERVER['SERVER_NAME'] part to http://www.yourdomain.com , and this can be good in case you change your domain name, or if you decide to use the code in other domains without having to manually change your hardcoded domain.tld

Perfect. Thank you.