https for only some views? |
[eluser]Unknown[/eluser]
[quote author="nevercraft" date="1220609256"]Although this thread is a few months old, I thought I'd share the way I accomplished this with just a simple helper function. Code: if ( ! function_exists('force_ssl')) Simply call force_ssl() from within any controller method (or the constructor). The user will be redirected to https:// if needed. Also, https:// will show up correctly on any of the other URL helpers used AFTER force_ssl() is called.[/quote] Thanks, nevercraft - this worked perfectly. While the .htaccess solution is viable - it is not very dynamic
[eluser]GSV Sleeper Service[/eluser]
thanks nevercraft, force_ssl() is now a permanent addition to my helpers collection.
[eluser]Unknown[/eluser]
[quote author="nevercraft" date="1220609256"]Although this thread is a few months old, I thought I'd share the way I accomplished this with just a simple helper function. Code: if ( ! function_exists('force_ssl')) Simply call force_ssl() from within any controller method (or the constructor). The user will be redirected to https:// if needed. Also, https:// will show up correctly on any of the other URL helpers used AFTER force_ssl() is called.[/quote] The function works perfectly although at the beginning I had some problems because I didn't have 'http://' in my base_url. Also I was using .htaccess to get rid of index.php from url's and this function was redirecting using index.php, all I had to do was to set $config['index_page'] from config.php so it was blank. Maybe it will help someone.
[eluser]k00k[/eluser]
[quote author="Mahtar" date="1237770232"][quote author="nevercraft" date="1220609256"]Although this thread is a few months old, I thought I'd share the way I accomplished this with just a simple helper function. Code: if ( ! function_exists('force_ssl')) Simply call force_ssl() from within any controller method (or the constructor). The user will be redirected to https:// if needed. Also, https:// will show up correctly on any of the other URL helpers used AFTER force_ssl() is called.[/quote] The function works perfectly although at the beginning I had some problems because I didn't have 'http://' in my base_url. Also I was using .htaccess to get rid of index.php from url's and this function was redirecting using index.php, all I had to do was to set $config['index_page'] from config.php so it was blank. Maybe it will help someone.[/quote] Thanks, that did help me as well. Also, please note, you must be using the URL helper as well because force_ssl() calls the redirect() function. Either in your controller or in your autoload config file. $this->load->helper('url');
[eluser]Andrew G.[/eluser]
For an alternate solution to this - using a customised Config class and hook - check out this thread: http://ellislab.com/forums/viewthread/131918/
[eluser]Unknown[/eluser]
Hi All, I'm trying to use the helper function below but I am getting a "The page isn't redirecting properly" error when navigating to a controller where force_ssl() is called. Any ideas why this might be? [quote author="nevercraft" date="1220609256"]Although this thread is a few months old, I thought I'd share the way I accomplished this with just a simple helper function. Code: if ( ! function_exists('force_ssl')) Simply call force_ssl() from within any controller method (or the constructor). The user will be redirected to https:// if needed. Also, https:// will show up correctly on any of the other URL helpers used AFTER force_ssl() is called.[/quote] This is the contents of my htaccess file - could there by a conflict in here? Code: <IfModule mod_rewrite.c>
[eluser]ali oygur[/eluser]
hi everybody I m little speak english. im use this way Code: <?php $base_url = (@$_SERVER['HTTPS'])? preg_replace('/http:/', 'https:', base_url()) : base_url(); ?> example: this is my header view file location: ./aplication/view/inc/header.php Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> how do you think ?
[eluser]C4iO [PyroDEV][/eluser]
Hi there.... I just want to share a quick update to nevercraft's solution. In force_ssl_helper.php, I've added a function to remove SSL if it isn't needed, as follows: Code: if ( ! function_exists('force_ssl')) but where does the page knows to use or not SSL? Simply enough. Just add the following code to the very top of your page: Code: <?php than you just have to create an item in the config file called 'ssl_pages' that is a single dimension array with the controller names that you which to force SSL to. EXAMPLE: If I have a header file which is called on every view page and a controller named My_secure_checkout, than I'll have to do this: 1. Create a helper file named force_ssl_helper.php in my application/helpers folder and paste the code I've mentioned earlier on this post. 2. On header.php file or whatever you name it, paste the following code to the very top: Code: <?php 3. On config.php, add the following line to the very end: Code: $config['ssl_pages'] = array('my_secure_checkout'); and.... Voilá! Now I have My_secure_checkout controller using SSL, leaving others untouched. I know this is not the best solution, but it works fine for me. I hope it can help somebody. HAPPY CODING....
[eluser]Unknown[/eluser]
force_ssl_helper.php may not be useful when you send an HTTP request with POST method to execute an action(function), which is required SSL. When redirect() is executed, it sends an GET HTTP request via https to execute the same action, but the data of POST is lost. There is an example: Code: class Welcome extends Controller { When the login form is submitted, browser sends a request using POST method to http://192.168.1.1/index.php/welcome/authenticate, and it is redirected to https://192.168.1.1/index.php/welcome/authenticate at once, because this action requires SSL. Unfortunately, I can not retrieve email and password any more.
[eluser]manisha[/eluser]
I have tried all the suggestions in this thread for Htaccess to remove index.php from Code Igniter URL. This rewrite rules removes index.php from URL but does not display under Secure URL. for example: http://www.mysite.com/CodeIg/MyController -- Works perfect https://www.mysite.com/CodeIg/index.php/MyController -- Works perfect But https://www.mysite.com/CodeIg/MyController -- Does not Work at all. It gives page not found server error. Then I tried adding the htaccess rules in Virtual host file... Now the Screen get displayed but without any css, js and Images included in the page. All these folder like css, images and JS are in application directory. Does anyone know why this problem is coming? REply to post would be appreciated a lot.... Thanks |
Welcome Guest, Not a member yet? Register Sign In |