Redirect http to https in codeigniter

Follow below steps to redirect you non-http site to https without using .htaccess

  • Change Configuration: go to application/config/config.php and enable hooks to true
            $config['enable_hooks'] = TRUE;
  • Create new file hooks.php if not exist other wise open file and paste code
          $hook['post_controller_constructor'][] = array(
                                'function' => 'redirect_ssl',
                                'filename' => 'ssl.php',
                                'filepath' => 'hooks'
                                );
  • Now create a new folder hooks if not exist under application folder and then create new file ssl.php and add below code to ssl.php
 <?php
function redirect_ssl() {
    $CI =& get_instance();
    $class = $CI->router->fetch_class();
    $exclude =  array('client');
    if(!in_array($class,$exclude)) {
      $CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);
      if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string());
    } 
    else {
      $CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']);
      if ($_SERVER['SERVER_PORT'] == 443) redirect($CI->uri->uri_string());
    }
}
?>

Comments

  1. In fact I just understand most people, Nowadays complete a latest Redirect Http to Http tow hooks if you are not are in existence according to utility folder and next design latest register ssl. php not to mention insert following coupon towards ssl. php.

    ReplyDelete
  2. Chrome and Firefox have started showing insecure warnings on sites without SSL certificates. Without SSL, your website will show insecure to the visitors. Therefore, using an SSL-encrypted connection for safety, accessibility or PCI compliance reasons is necessary. It becomes very important to redirect from HTTP to HTTPS.
    for more information click here: HOW TO REDIRECT HTTP TO HTTPS

    ReplyDelete
  3. The best crypto casino - Dr.MCD
    We 대전광역 출장마사지 have made a list of the 의왕 출장마사지 best crypto casino sites, providing the best crypto casino software 충청남도 출장샵 for 원주 출장샵 you to 제주도 출장마사지 play casino games in your browser. We rank them based on

    ReplyDelete
  4. 0propexQtinc-ji Renee Taylor click
    ularlialong

    ReplyDelete

Post a Comment

Popular posts from this blog

Creating Protected routes in ReactJS