Re: path issue with CSS [-RESOLVED-]

Web hosting discussion, programming, and shared and dedicated servers.
4 posts Page 1 of 1
by racerlupine » Sat Sep 14, 2019 10:20 am
At the top of a PHP file I declare a variable then use it to point to some files I want to include.

Thus sindext.php:

Code: Select all

  include "$siteroot/inc/hdr-sin1.php";
<title>]nlr[ HOME PAGE</title>
<?php include "$siteroot/inc/hdr-sin2.php"; ?>

[some html goes here]

<?php include "$siteroot/inc/ftr-sin.php"; ?>

The hdr-sin1.php:

Code: Select all

<!DOCTYPE html>
<html lang="en"><head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
<link rel="stylesheet" type="text/css" href="<?php echo "$siteroot/inc/sin.css"; ?>">

...and the hdr-sin2.php:

Code: Select all

</head><body id="bodyxx">

Lastly the tree:


Please note that the first thing I do is declare the variable; and that the CSS and the includes are in the same directory.

The issue: When I open the page in the browser and look at the generated HTML the URLs are rendered correctly. However while the PHP includes work perfectly, the CSS does not. I'm using the same variable for the includes and the stylesheet; the first works the second does not.

When I use the absolute path without the variable for the <link> the CSS still does not work. I've tried several ways of stating the absolute path, with and without the variable: http://[domain][path], /nfs/www[path], I've checked them carefully, same results.

The EXACT SAME PATH works for the includes but not for the CSS.

What am I missing?


by racerlupine » Sat Sep 14, 2019 1:41 pm
hmmm...ya know, the last time something like this came up the problem was in the external stylesheet, not in the code...hmmmm...think I'll have a look at that...
by racerlupine » Sat Sep 14, 2019 1:44 pm
I forgot to mention: the console shows a 404 when it looks for sin.css.

by racerlupine » Thu Sep 19, 2019 3:54 am
It turns out the path needs separate variables:

Code: Select all


$csspath and $incpath point to the same directory, but are not interchangeable -- not if you're using external CSS and PHP includes together. And creating the paths off of $rootpath doesn't work for CSS but works for PHP. I use $rootpath to link to files not in $incpath.

So this is what works, I'm not smart enough to explain why.

hope this helps

4 posts Page 1 of 1

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests (based on users active over the past 5 minutes)
Most users ever online was 999 on Mon May 10, 2021 1:02 am

Users browsing this forum: No registered users and 4 guests