Home  >  Article  >  Backend Development  >  网站首页 有时加载不了样式

网站首页 有时加载不了样式

WBOY
WBOYOriginal
2016-06-23 13:51:081159browse

做的一个网站,首页有缓存  有时候打开的时候 样式的路径是这样 的   ip地址/css/index.css  首页样式乱了   这个网站一开始用ip:8080访问  绑上域名以后域名访问  但是有时候样式 还是加载的ip的   清除缓存以后  样式的路径换上 域名/css/index.css  首页样式就正常了  首页的缓存采用的是文件缓存

样式的路径采用的是这个函数获得的

function get_http(){    return isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off' ? 'https://' : 'http://';}function get_domain(){    $protocol = get_http();    if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {        $host = $_SERVER['HTTP_X_FORWARDED_HOST'];    } elseif (isset($_SERVER['HTTP_HOST'])) {        $host = $_SERVER['HTTP_HOST'];    } else {        if (isset($_SERVER['SERVER_PORT'])) {            $port = ':' . $_SERVER['SERVER_PORT'];            if (':80' == $port && 'http://' == $protocol || ':443' == $port && 'https://' == $protocol) {                $port = '';            }        } else {            $port = '';        }        if (isset($_SERVER['SERVER_NAME'])) {            $host = $_SERVER['SERVER_NAME'] . $port;        } elseif (isset($_SERVER['SERVER_ADDR'])) {            $host = $_SERVER['SERVER_ADDR'] . $port;        }    }    return $protocol . $host;}


回复讨论(解决方案)

ip地址/css/index.css

这里不是应该ip地址 :8080/css/index.css

ip地址/css/index.css

这里不是应该ip地址 :8080/css/index.css

   有道理

ip地址/css/index.css

这里不是应该ip地址 :8080/css/index.css

 本来应该显示ip:8080 的但是获得是ip 没有带端口,而且现在已经绑定域名了 偶尔还是获得ip 不带端口号  但是清除一下程序的缓存就好了,我想着是不是偶尔服务服务器不稳定 造成获得不了域名呢 

那什?情?下?使用IP???

那什?情?下?使用IP???

  这个不确定,网站的首页有10分钟的缓存,会在10分钟过后重新缓存,有时候访问访问着样式就乱了,所以才猜有可能是服务器不稳当

你的网站会是在 http 和 https 间切换吗?
只有在发生切换时才需要产生完整的 url

你 12 行起的,处理端口的代码在什么情况下会执行呢?($_SERVER['HTTP_HOST'] 总是存在的)
处理端口(PORT)和处理 HOST 是平行的,不应该放在 else 分支中

谢谢版主热心回答

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn