Codeigniter 回显 [::1] 而不是 localhost [英] Codeigniter echoing [::1] instead of localhost

查看:27
本文介绍了Codeigniter 回显 [::1] 而不是 localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 CodeIgniter 3 作为网络平台并尝试将语义 UI CSS 导入我的页面.我是通过在 CSS 导入的 href 属性中使用 CodeIgniter 的 base_url() 方法来实现的.

但是,semantic.css 本身会导入我服务器上存在的一些其他字体,由于跨域资源共享策略,这些字体随后无法加载.这是 chrome 给我的错误消息:

来自源 'http://[::1]' 的字体已被跨源资源共享策略阻止加载:不存在 'Access-Control-Allow-Origin' 标头在请求的资源上.因此不允许访问源 'http://localhost'.

这是因为 base_url() 回显了域是 [::1] 而不是我在浏览器中输入的 localhost.

出于某种原因,在我看来,chrome(以及 Edge)并未将 [::1] 和 localhost 视为同一主机,或者我可能只是愚蠢.我所知道的是,如果我更改主语义.css 文件的路径并将 localhost 硬编码到其中,它就可以工作,并且如果我使用 [::1]

我做过与此非常相似的其他项目,但从未出现过这个 "[::1]".究竟是什么导致 php 回显这样的路径?

解决方案

这是因为你的 base_url 为空.

config/config.php

$config['base_url'] = 'http://localhost/project_name';

<块引用>

关于 http://[::1]/

I am using CodeIgniter 3 as a web platform and trying to import semantic-UI CSS into my page. I'm doing so by using CodeIgniter's base_url() method in the href property for the CSS import.

However, semantic.css itself imports some other fonts present on my server, which are then unable to load because of Cross-Origin resource sharing policy. This is the error message chrome gives me:

Font from origin 'http://[::1]' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

This is because base_url() echoes the domain has being [::1] and not localhost as I've typed into the browser.

For some reason, it appears to me that chrome (and also Edge) does not consider [::1] and localhost as the same host, or maybe I'm just being dumb. What I know though is that if I change the path of the main semantic.css file and hard code localhost into it, it works, and it also works if, instead of requesting my page using localhost, I use [::1]

I've done other projects very similar to this and never had this "[::1]" appear. What exactly is causing php to echo such a path ?

解决方案

It's because of your base_url is empty.

In config/config.php

$config['base_url'] = 'http://localhost/project_name';

Something more interesting about http://[::1]/

这篇关于Codeigniter 回显 [::1] 而不是 localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆