首页 > 建站经验 > 完美解决emlog使用SSL,https访问的问题
2020
11-01

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

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

一、下载emlog SSL访问插件

下载地址:https://www.0792pz.com/content/uploadfile/201903/f66c1552971903.zip

备用地址:下载

安装插件后,启用之。

微信截图_20190322190935.png

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

二、修改代码

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

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

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

1.jpg

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

  

2.jpg
三、如果网站使用http访问就强制转向https 在你的模板下的header.php中增加以下代码
位置如图

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

OK,用https访问吧!

转载自李友亮博客。https://www.0792pz.com/bj/123.html


最后编辑:
作者:萌小白
一个热爱网络的青年!

发布评论

表情