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

WBOY
Release: 2016-06-13 12:05:20
Original
981 people have browsed it

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

本帖最后由 yang131261 于 2014-08-15 18:17:14 编辑 做的一个网站,首页有缓存  有时候打开的时候 样式的路径是这样 的   ip地址/css/index.css  首页样式乱了   这个网站一开始用ip:8080访问  绑上域名以后域名访问  但是有时候样式 还是加载的ip的   清除缓存以后  样式的路径换上 域名/css/index.css  首页样式就正常了  首页的缓存采用的是文件缓存

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

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

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

你 12 行起的,处理端口的代码在什么情况下会执行呢?($_SERVER['HTTP_HOST'] 总是存在的)
处理端口(PORT)和处理 HOST 是平行的,不应该放在 else 分支中
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template