简体   繁体   English

在Chrome中,基于$ _SERVER ['HTTP_HOST']的PHP加载CSS失败

[英]PHP load CSS based on $_SERVER['HTTP_HOST'] fails in Chrome

I'm trying to load a CSS file from a directory based on a dynamic filename generated with PHP $_SERVER['HTTP_HOST']. 我正在尝试从基于PHP $ _SERVER ['HTTP_HOST']生成的动态文件名的目录中加载CSS文件。 The idea being $_SERVER['HTTP_HOST'] is queried and matched to a client id. 查询想法$ _SERVER ['HTTP_HOST']并将其与客户端ID匹配。 That id is used in the CSS filename ie "1.css" or "5.css" in the html head depending on the client id. 该ID用于CSS文件名,即html头中的“ 1.css”或“ 5.css”,具体取决于客户端ID。

This method seems to be working in Safari and Firefox but just loads ".css" in google chrome on my mac. 这种方法似乎可以在Safari和Firefox中使用,但只能在我的Mac上的Google chrome中加载“ .css”。

Since PHP is server-side I can only assume it's the $_SERVER['HTTP_HOST'] which is not being picked up via Chrome. 由于PHP是服务器端的,所以我只能假设它不是通过Chrome获取的$ _SERVER ['HTTP_HOST']。

Two questions. 两个问题。 Why? 为什么? And - since this is a serious issue - what are my alternatives for dynamically writing the .css filename? 并且-由于这是一个严重的问题-动态写入.css文件名的替代方法是什么?

Thanks! 谢谢!

// Set client ID for session
$id_client_sql = "SELECT id FROM client WHERE url='".$_SERVER['HTTP_HOST']."'";
$id_client_res =  mysqli_query($dbConnect, $id_client_sql) or die(mysqli_error($dbConnect));

$client = mysqli_fetch_array($id_client_res);
$id_client = $client['id_client'];

Then - 然后 -

$display_block .= '<link  rel="stylesheet" href="'.$id_client.'.css">'; //etc...

Use $_SERVER['SERVER_NAME'] instead in Chrome. 在Chrome中使用$_SERVER['SERVER_NAME']代替。 I know this one was solved already but I encountered a blank HTTP_HOST in Chrome and trying SERVER_NAME instead fixed it. 我知道这个问题已经解决,但是我在Chrome中遇到了一个空白的HTTP_HOST ,然后尝试使用SERVER_NAME修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM