Tenaciousmug Posted February 26, 2012 Share Posted February 26, 2012 Okay the reason I'm doing it this way is because I work locally and then transfer them to the production site. For some reason, this isn't working even though when I view the page source, it has the right URL, but when it's clicked it goes to a blank page, but when I copy and paste, it goes to the right page. Anywho, this is what I'm trying: <?php $homeURL = 'localhost:90/Elvonica'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Elvonica</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <link rel="stylesheet" type="text/css" href="<?php echo $homeURL; ?>/template/css/skySpirit.css" /> I didn't plug in the rest to ignore it since it's not part of the problem. It's printing: localhost:90/Elvonica/template/css/skySpirit.css, but when it's clicked, goes to blank page. When it is copied and pasted, it goes to the right page. I have a feeling you can't include PHP inside a link rel or any sort of that header information. If anyone could please help me how to do this, I would appreciate it. FYI: I did have just template/css/skySpirit.css and it worked until I go into a another directory like forums/index.php. Then it tries to go localhost:90/Elvonica/forums/template/css/skySpirit.css and it's not in there obviously. Thank you for anything that you can offer! I know how to do the includes with the dirname(__FILE__). Quote Link to comment https://forums.phpfreaks.com/topic/257797-css-not-loading-from-external-stylesheet/ Share on other sites More sharing options...
Psycho Posted February 26, 2012 Share Posted February 26, 2012 There is no problem with using PHP to dynamically set ANY values in the HTML code - even the href for the style sheet. So, not sure what your problem is, but you don't need to set the value that way. As you found, when using "template/css/skySpirit.css" it will not find the style sheet with opening pages in sub folders. There is a very simple solution. Just put a slash at the beginning of the path and that will search from the root of the site rather than the root fo the current page location. <link rel="stylesheet" type="text/css" href="/template/css/skySpirit.css" /> Quote Link to comment https://forums.phpfreaks.com/topic/257797-css-not-loading-from-external-stylesheet/#findComment-1321318 Share on other sites More sharing options...
Tenaciousmug Posted February 26, 2012 Author Share Posted February 26, 2012 Yeah if I put the slash infront of it, it shows this: http://localhost:90/template/css/skySpirit.css It doesn't include my /Elvonica folder that I have the whole solution in. I don't know how to fix that. I know it would probably work on the public server, but not my localhost machine since I have to put the whole project in a solution. Quote Link to comment https://forums.phpfreaks.com/topic/257797-css-not-loading-from-external-stylesheet/#findComment-1321320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.