Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have CodeIgniter load specific pages using SSL?

Tags:

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 pages. For example, https (port 443) would serve pages out of /var/www/ssl_html/ And http (port 80) serves pages out of /var/www/html/. How would I get CodeIgniter to play nice with this setup?

like image 899
ammonkc Avatar asked Sep 30 '09 20:09

ammonkc


People also ask

Does CodeIgniter support SSL on Apache?

I have a Codeigniter application which was developed and tested on the normal http. Now the Apache server has been configured in such a way that all of the pages are stored in a single folder which is SSL enabled. The SSL certificate is in place. When I browse to the website using "https://www" then it redirects to "http://www".

How do I start CodeIgniter on a localhost server?

CodeIgniter has its own command that you can use though. will start a web server, accessible on port 8080. If you set the location field in your browser to localhost:8080, you should see the CodeIgniter welcome page. You can now try several URLs in the browser location field, to see what the Pages controller you made above produces…

What does the new pages class do in CodeIgniter?

This means that the new Pages class can access the methods and variables defined in the CodeIgniter\Controller class ( system/Controller.php ). The controller is what will become the center of every request to your web application.

How do I handle static pages in CodeIgniter?

This tutorial assumes you’ve downloaded CodeIgniter and installed the framework in your development environment. The first thing you’re going to do is set up a controller to handle static pages. A controller is simply a class that helps delegate work. It is the glue of your web application. For example, when a call is made to:


2 Answers

There are few ways to tackle this.

Option 1:

I would probably have the code deployed to both folders, then in the file: /system/application/config/config.php, set your page to:

$config['base_url'] = "http://www.yoursite.com/"; 

or

$config['base_url'] = "https://www.yoursite.com/";

Then in your non-ssl VirtualHost folder, set your config to redirect protected pages by folder to the SSL site:

RedirectPermanent /sslfolder https://www.yoursite.com/sslfolder

Option 2:

Send everything to SSL and keep all your code in one folder

/system/application/config/config.php, set your page to:

$config['base_url'] = "https://www.yoursite.com/";

Other Options

There are some more hacky ways to do this with header() redirects, etc. but I don't think you want to maintain different code bases for this option. I don't recommend this but you could do something like:

$config['base_url'] = “http://” . $_SERVER['http_host'] . “/”;
like image 93
randomx Avatar answered Oct 22 '22 00:10

randomx


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.

like image 34
skyler Avatar answered Oct 21 '22 23:10

skyler