PHP css包含[关闭]

I'm having trouble with css style sheets loading on my test site. Here's a my issue.

I have a navigation page called '_navTop.php'. At the top within the file I have this PHP line:

<?php include ('css.php'); ?>

the css.php file contains the following:

<?php
      $incPath = $_SERVER['DOCUMENT_ROOT'] . '/php_test/includes/';
      echo '<link href="'.$incPath.'css/main.css" rel="stylesheet">';
?>

When I inspect the page in Firefox, I see this:

<!DOCTYPE html>
 <html>
 <head>
 <link href="C:/xampp7/htdocs/php_test/includes/css/animate.css" rel="stylesheet">
 </head>
 </html>

The page is not loading the css file and formatting. The path the css file checks out. Any ideas on the problem?

Change

$incPath = $_SERVER['DOCUMENT_ROOT'] . '/php_test/includes/';

to

$incPath = $_SERVER['HTTP_HOST'] . '/php_test/includes/';

DOCUMENT_ROOT is the current directory internally (as you can see from the URL it provides) which is only usable on server-side code (not on direct output - i.e: includes).

This is what you said you loaded

echo '<link href="'.$incPath.'css/main.css" rel="stylesheet">';

but what was rendered is

 <link href="C:/xampp7/htdocs/php_test/includes/css/animate.css" rel="stylesheet">

How did main.css turn to animate.css ? Please check.

Well this is quite tricky though. Replace

$_SERVER['DOCUMENT_ROOT']

with

$_SERVER['SERVER_ADDR']

This should help.