Codeigniter: how to use secure urls along with normal url
How can I use HTTPS along with HTTP in codeigniter and in its开发者_运维技巧 base_url.
Note sure about the link generation, yet I might be able to help you with the base URL. PHP usually offers you the $_SERVER array which is available within the config files. So instead of hard coding the Base URL I usually make it dynamic using the server URL. Same works with the HTTPS status. Untested but should work:
$config['base_url'] = sprintf('%s://%s/', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'), $_SERVER['HTTP_HOST']);
Be careful when using the HTTPS index. I've read about setups where its 1 instead of on. You better probe your server variables using phpinfo().
cu Roman
If you use Codeigniter 2.0 and above,
You need not to specify base_url in the config file rather if you let it empty, it automatically detects whether it may be a HTTP or HTTPS url.
精彩评论