php - 使用 PHP 静态文件加载器加载 CSS 样式时出现问题

标签 php css security apache .htaccess

我正好有the same problem treated in this topic .那是:我在某些文件夹中有一些静态文件,我希望只有一些用户可以看到该内容。用户来自以前的登录。

为此,我正在尝试实现本主题中给出的第一个解决方案,即:

Create the following .htaccess file under "static-files":

Options +FollowSymLinks  
RewriteEngine on  
RewriteRule ^(.*)$ ../authorize.php?file=$1 [NC]

And then in authorize.php...

if (isLoggedInUser()) readfile('static-files/'.$_REQUEST['file']);
else echo 'denied';

This authorize.php file is grossly over simplified, but you get the idea.kquote

因此,将任何请求重定向到 authorize.php 文件,该文件检查用户是否已登录,如果是,则提供内容。

这与 html、js 和图像完美配合……但我不知道为什么不显示 css 样式。这很奇怪,因为我可以直接用我的浏览器访问那个 css 文件,但是当它们从 html 调用时它不起作用。当然,如果我尝试在没有 authorize.php 的情况下工作,样式会照常显示。

我错过了什么?

谢谢,

最佳答案

您可能没有发送正确的 content-type header 。这使得样式表在 Firefox 中失败。

做一个

header("Content-type: text/css");

每当请求 CSS 样式表时。

关于php - 使用 PHP 静态文件加载器加载 CSS 样式时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7558055/

相关文章:

php - Bootstrap 足球队动态布局

html - 与 float 和宽度有关

jquery - ie6 悬停和 jquery 错误

python - 使用 python SMTP 库凭据安全发送电子邮件

javascript - 为什么内联 JavaScript 安全性不好?

javascript - 从服务器读取另一台机器的文件

php - while($row = mysqli_fetch_array($result)){ 选择多个表时

javascript - jQuery 按 id 删除

php - 使用包含两个元素的关联数组在多维数组中搜索唯一行

javascript - 如何调用函数以在 jquery 移动站点中自动加载元素