<链接>上的子请求


A sub-request on a <link>

<img src="test.php" alt="">时,将执行PHP脚本。为什么我不能对以下方法做同样的事情:

<link rel="stylesheet" href="css/test.php">

你可以。 在发送任何输出之前,只需确保将 php 文件顶部的标头设置为 text/css。 此外,您可能还想在其上设置一些缓存,我的偏好是远期,然后在更改 css 时更改文件名。

<?php
header("Content-Type: text/css; charset=utf-8");    //make the browser see this as a valid CSS file
header("Cache-Control: public, max-age=31536000");  //long in the future for requestless caching

问题可能是标头,请在测试.php脚本中包含此标头

<?php
  header('Content-type: text/css');
  /*your css below*/
?>

我希望它可以解决您的问题