douduan3203 2017-08-13 23:33
浏览 42

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?

  • 写回答

3条回答 默认 最新

  • dpjpo746884 2017-08-13 23:39
    关注

    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).

    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3