Skip to content

Instantly share code, notes, and snippets.

@demogar
Created August 9, 2011 04:45
Show Gist options
  • Select an option

  • Save demogar/1133428 to your computer and use it in GitHub Desktop.

Select an option

Save demogar/1133428 to your computer and use it in GitHub Desktop.
Archivo de configuracion para las rutas con seguridad
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
class MY_Controller extends CI_Controller
{
function __construct()
{
parent::__construct();
if (in_array($this->uri->segment(1), $this->config->item('ssl_pages'))) {
force_ssl();
} else {
remove_ssl();
}
}
}
/* End of file: MY_Controller.php */
<?php if (!defined('BASEPATH')) exit('No direct script access allowed.');
function force_ssl()
{
if (ENVIRONMENT != "development") {
$CI =& get_instance();
$CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);
if ($_SERVER['SERVER_PORT'] != 443) {
redirect($CI->uri->uri_string());
}
}
}
function remove_ssl()
{
if (ENVIRONMENT != "development") {
$CI =& get_instance();
$CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']);
if ($_SERVER['SERVER_PORT'] != 80) {
redirect($CI->uri->uri_string());
}
}
}
/* End of file: ssl_helper.php */
<?php if (!defined('BASEPATH')) exit('No direct script access allowed.');
// ...
$config['ssl_pages'] = array('profile', 'tienda', 'pedidos');
// ...
/* End of file: ssl_routes.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment