php 如何在 CodeIgniter 中将动态基本 url 设置为 https?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20415025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:10:45  来源:igfitidea点击:

How to set Dynamic base url to https in CodeIgniter?

phpcodeigniter

提问by DNB5brims

I try the use a dynamic base url in this post:

我尝试在这篇文章中使用动态基本网址:

Set Dynamic Base Url in CodeIgniter

在 CodeIgniter 中设置动态基本 URL

But I used to be use the http, but now, I would like to change to https, how can I do so? Thanks.

但是我以前是用http的,现在想换成https,怎么办?谢谢。

回答by Richat CHHAYVANDY

In your config/config.php, try this:

在你的 config/config.php 中,试试这个:

$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

回答by ARIF MAHMUD RANA

You can use codeigniter hooksin pre_controller you just change the base_url http to https by string replace and set the base url

您可以在 pre_controller 中使用codeigniter 钩子,您只需通过字符串替换将 base_url http 更改为 https 并设置基本 url

回答by Manoj Singh

$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];

$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];

this works for me with virtualhost setup.

这适用于我的虚拟主机设置。