chordsoflife Posted November 20, 2007 Share Posted November 20, 2007 So here's my situation: I've created header/footer files, and included them in all the pages of my website. My problem is that in the header file, I have link href="css/default.css" rel="stylesheet" type="text/css" which doesn't apply for each page, since I have some pages in folders for organizational issues. Is there a way to make that reference dynamic somehow? I don't even know if my thinking is correct. I've seen $_SERVER['DOCUMENT_ROOT'] been used, but tried it and received errors. I'm not sure if I set it up correctly. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/78010-solved-header-css-location-help/ Share on other sites More sharing options...
pkSML Posted November 20, 2007 Share Posted November 20, 2007 I believe you're saying you're putting the link to the CSS file in each page of your site. And some of these pages reside in a different folder, so the path to the CSS is wrong. If so, your URL just needs to be spruced up a little. From the root of your domain, trace the path. If CSS is a directory under the root directory, your code would be: <link href="/css/default.css" rel="stylesheet" type="text/css"> Notice the slash beginning the URL. That will make all the difference. Link to comment https://forums.phpfreaks.com/topic/78010-solved-header-css-location-help/#findComment-394858 Share on other sites More sharing options...
chordsoflife Posted November 20, 2007 Author Share Posted November 20, 2007 I tried that and it didn't work. My files aren't under the root, they're above it, so on most, the css file would be located at "css/default.css" but for others it would be "../../css/default.css". My issues is that I'd like to use the same header file (which contains the link line) for all of my files. I definitely appreciate the help. The ball is rolling. Link to comment https://forums.phpfreaks.com/topic/78010-solved-header-css-location-help/#findComment-394877 Share on other sites More sharing options...
bruckerrlb Posted November 20, 2007 Share Posted November 20, 2007 Just an idea, and maybe it's going to be a bit backwards, but if you created a database and put the path to your stylesheets in that database, then do a query something like (and this is not proper syntax) SELECT * FROM stylesheets WHERE page_id = 'trees' Then put the data returned into a variable, you could have your link as such <link href="<? php echo $trees; ?> /> Just an idea Link to comment https://forums.phpfreaks.com/topic/78010-solved-header-css-location-help/#findComment-394878 Share on other sites More sharing options...
chordsoflife Posted November 20, 2007 Author Share Posted November 20, 2007 Unfortunately I don't have mysql installed on this server. I'm working on this project on my university's webspace until it's ready to be hosted. Thanks for the idea though! Link to comment https://forums.phpfreaks.com/topic/78010-solved-header-css-location-help/#findComment-394880 Share on other sites More sharing options...
pkSML Posted November 20, 2007 Share Posted November 20, 2007 Just use an absolute URL then. It'll never steer you wrong. Example: http://you.edu/~you/path/css/file.css Just use the full URL because it won't change. Link to comment https://forums.phpfreaks.com/topic/78010-solved-header-css-location-help/#findComment-395098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.