使用ip地址的HTTPS背景图片?

时间:2013-09-25 15:56:33

标签: php css ssl https background-image

我有一个使用CodeIgniter的网站(一个旧版本已被多个开发人员随着时间的推移而升级)。该网站使用HTTP工作100%(我的测试环境不能使用HTTPS)但是当我切换到HTTPS时,所有的CSS背景图像切换到使用IP地址?

Background Images are missing The CSS is using the IP Address

在每个页面中,我都包含以下代码段以便于使用,但它生成相同的IP地址,因此我发现问题出在site_url()函数中 - image_url()只是添加到{{ 1}}。

site_url()

Site_url() is returning the IP Address

我没有“实时测试环境”来测试更改并且难以接受。我相信下面覆盖的函数<script type="text/javascript"> var BASE_URL = '<?= site_url() ?>'; // http://555.555.55.555/ var IMG_PATH = '<?= image_url() ?>'; // http://555.555.55.555/images/main </script> 可能存在问题,但不知道为什么或导致问题的原因。 (force_ssl()函数来自here。)

我正在使用CodeIgniter force_ssl()插件来提供CSS / JS并具有以下功能来强制carabiner中的SSL / HTTPS:

my_helper.php

有更好的方法吗? (即从HTTP切换到HTTPS)和/或我的if (!function_exists('force_ssl')) { function force_ssl() { if (ENVIRONMENT != 'development') { $CI = & get_instance(); $CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']); if ($_SERVER['SERVER_PORT'] != 443) { redirect($CI->config->config['base_url'] . $CI->uri->uri_string()); } } } } /** * Override the site_url function so it does https * * @param <type> $uri * @return <type> */ function site_url($uri = '', $https = FALSE, $only_images_js_css = true) { if ($https || (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443)) { if (ENVIRONMENT != 'production') { $secure_connection = FALSE; } else { $secure_connection = TRUE; } } else { $secure_connection = FALSE; } $CI = & get_instance(); if (!$secure_connection) { return str_replace("https://", "http://", $CI->config->site_url($uri)); } else { // fallback - .htaccess should cover this - but just to make sure... // If we only want the images, js, css, etc. to have https:// if ($only_images_js_css === true) { $needs_ssl = false; $extensions_to_check = array(".js", ".css", ".jpg", ".gif", ".png", ".ico"); foreach ($extensions_to_check as $extension_to_check) { if (stristr($uri, $extension_to_check) !== FALSE) { $needs_ssl = true; break; } } if ($needs_ssl === true) { return str_replace("http://", "https://", $CI->config->site_url($uri)); } else { return str_replace("https://", "http://", $CI->config->site_url($uri)); } } else { return str_replace("http://", "https://", $CI->config->site_url($uri)); } } } 和/或site_url()功能有什么问题?

2 个答案:

答案 0 :(得分:1)

我不确定这个问题与这些功能有关。他们从base_url配置获取数据。如果未设置base_url,Codeigniter会尝试猜测the protocol, domain and path to your installation.我认为这是服务器设置问题,因为Codeigniter使用$_SERVER['HTTP_HOST']来获取域/ ip。

if ($this->config['base_url'] == '')
{
    if (isset($_SERVER['HTTP_HOST']))
    {
        $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
        $base_url .= '://'. $_SERVER['HTTP_HOST'];
        $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
    }
    else
    {
        $base_url = 'http://localhost/';
    }

    $this->set_item('base_url', $base_url);
}

答案 1 :(得分:0)

问题原来是我的CSS放大倍数的一部分(之前已被修改以允许重新配置CodeIgniter文件夹)

使用codeigniter Carabiner插件 - cssmin.php是问题的文件.... https://github.com/tonydewan/Carabiner