How can I have CodeIgniter load specific pages using SSL?

前端 未结 10 1144
礼貌的吻别
礼貌的吻别 2020-11-30 06:40

How can I have CodeIgniter load specific pages using SSL? I have an apache2/mode_ssl server. mod_ssl uses a different document root than non-secure

相关标签:
10条回答
  • 2020-11-30 07:21

    Here's a good solution. http://sajjadhossain.com/2008/10/27/ssl-https-urls-and-codeigniter/

    0 讨论(0)
  • 2020-11-30 07:23

    In application/config/config.php, set base_url to:

    $config['base_url'] = ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://{$_SERVER['HTTP_HOST']}/";

    This will allow it to work on any domain, which is convenient if you test locally.

    0 讨论(0)
  • 2020-11-30 07:27

    This is what worked for me. Our server both have $_SERVER['SERVER_PORT'] and $_SERVER['HTTP_X_FORWARDED_PORT']

    We should check first if $_SERVER['HTTP_X_FORWARDED_PORT'] is available and use this instead of $_SERVER['SERVER_PORT']

    $config['base_url'] =
    ( ( ( empty($_SERVER['HTTP_X_FORWARDED_PORT']) ? $_SERVER['SERVER_PORT'] : $_SERVER['HTTP_X_FORWARDED_PORT'] ) == 443 ? 'https' : 'http') . "://" . $_SERVER['HTTP_HOST'] )
    . str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']) ;
    

    tested this on our linux server...


    btw, it's based on skyler's answer before which was.

    $config['base_url'] = ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://{$_SERVER['HTTP_HOST']}/";
    
    0 讨论(0)
  • 2020-11-30 07:33

    the solution that came to my mind is to use str_replace() like so

    $base_url_str = base_url(); 
    $secure_base_url = str_replace("http","https",$base_url_str );
    

    whenever I need a secure location , i use $secure_base_url instead of base_url(), so let's say your base_url() is http://www.example.com then $secure_base_url will be https://www.example.com

    0 讨论(0)
提交回复
热议问题