emlog使用SSL,https访问的问题

2022年3月15日11:36:57 发表评论 729 views

一、下载emlog SSL访问插件

下载地址:

http://ctdown.wdooc.com/f/3437109-552082863-d07708

https://wwi.lanzouq.com/iJjdz010oe1g

链接: https://pan.baidu.com/s/11tLyiXAByOz-38AYF-6nMg?pwd=2dwy 提取码: 2dwy

安装插件后,启用之。

emlog使用SSL,https访问的问题

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

二、修改代码

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

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

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

emlog使用SSL,https访问的问题

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"));

 

 

emlog使用SSL,https访问的问题
三、如果网站使用http访问就强制转向https

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

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

 

emlog使用SSL,https访问的问题

OK,用https访问吧!

 

转载自:https://www.maimengkong.com/jzjy/650.html

历史上的今天:


欢迎来到菜鸟头头的个人博客
本文章百度已收录,若发现本站有任何侵犯您利益的内容,请及时邮件或留言联系,我会第一时间删除所有相关内容。

  • A+
所属分类:WEB

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: