EMLOG添加https支持加密协议的方法
对于站长朋友们来说,给网站添加https认证的好处自然是不少的,比如搜索引擎优先收录,优先抓取页面等等,现在就来为大家分享一下给EMLOG添加https支持加密协议的方法。
一、操作步骤
1、登陆FTP,打开/include/lib/option.php文件
2、将以下代码粘贴到第43行之前,即get function的default判断分支
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文件,在第39行找到如下代码
define('DYNAMIC_BLOGURL', getBlogUrl());
4、 将上述代码替换为如下代码
define('DYNAMIC_BLOGURL', Option::get("blogurl"));
5、 保存并上传所有的php文件,然后在网址前面加上https://试试效果吧
二、注意事项
1、使用本教程前,请先确认服务器已正确配置https,并使用专业编辑器打开上述PHP文件修,改前请做好数据备份工作
2、使用本教程前,如果确认使用的是EMLOG 5.3.1版本且没有对源代码进行过修改,可以下载博客志改好的文件直接覆盖同名文件
三、附件下载
EMLOG添加https加密协议大小:13KB | 来源:本站下载