完美解决emlog使用SSL,https访问的问题

emlog我就不说多了,说起来都是泪,不过还是有部分人在使用此博客,如何解决SSL访问的时候出现的一些问题,主要是分为两步走。

一、下载emlog SSL访问插件

地址:http://tv1314.com/post-433.html   ,作者鬼少,搬运工地址,安装插件后,启用之。

解决了这一部分,其实已经基本可以使用SSL访问了,但关系多众多模板的问题,这样还是不够的。

二、修改代码

修改代码前请先备份,这代码来自于其他网站,经过多个博客模板测试可行,版本仅限于5.3.1

1、 /include/lib/option.php
请将以下内容粘贴到 get function 的 default 判断分支之前 (在Emlog 5.3.1下是第43行)

case 'blogurl':
return realUrl();
break;

2、 /include/lib/function.base.php

请将以下内容粘贴到文件的末尾

/**
 * 获取当前访问的base url
 */
function realUrl() {
    static $real_url = NULL;
    if ($real_url !== NULL) {
        return $real_url;
    }
    $emlog_path = EMLOG_ROOT . DIRECTORY_SEPARATOR;
    $script_path = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
    $script_path = str_replace('\\', '/', $script_path);
    $path_element = explode('/', $script_path);
    $this_match = '';
    $best_match = '';
    $current_deep = 0;
    $max_deep = count($path_element);
    while($current_deep < $max_deep) {
        $this_match = $this_match . $path_element[$current_deep] . DIRECTORY_SEPARATOR;
        if (substr($emlog_path, strlen($this_match) * (-1)) === $this_match) {
            $best_match = $this_match;
        }
        $current_deep++;
    }
    $best_match = str_replace(DIRECTORY_SEPARATOR, '/', $best_match);
    $real_url  = $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://';
    $real_url .= $_SERVER["SERVER_NAME"];
    $real_url .= in_array($_SERVER['SERVER_PORT'], array(80, 443)) ? '' : ':' . $_SERVER['SERVER_PORT'];
    $real_url .= $best_match;
    return $real_url;
}

3、/init.php
请用以下代码覆盖同名的define (在Emlog 5.3.1下是第39行)

define('DYNAMIC_BLOGURL', Option::get("blogurl"));

三、如果网站使用http访问就强制转向https

在你的模板下的header.php中增加以下代码,位置如图.

if(!isset($_SERVER['HTTPS'])){
    Header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
} 

OK,用https访问吧!

THE END
打赏
海报
完美解决emlog使用SSL,https访问的问题
emlog我就不说多了,说起来都是泪,不过还是有部分人在使用此博客,如何解决SSL访问的时候出现的一些问题,主要是分为两步走。 一、下载emlog SSL访问插件 地址:http://tv1314.com/post-433.html   ,作者……
<<上一篇
下一篇>>