CodeIgniter Forums
Password Protecting App in Development - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Password Protecting App in Development (/showthread.php?tid=33859)



Password Protecting App in Development - El Forum - 09-10-2010

[eluser]vinoth15[/eluser]
Hello,

I am developing a web application using CI at www.thisapp.com (example
domain). My CI install is located outside the www root folder.

How do I go about password protecting my application while still allowing
my "home page" (in this case the default controller/view in CI ) to be
publically accessible ?

I.E. I want to develop my application without any authorized users (i.e.
the public) poking around, but still want a landing page to be visible.

I've been able to use .htaccess to password protect my entire www root, is
there anyway to exclude the home page from protection ? And if so, what
file would I exclude in my CI setup ?

Thanks again. I hope that makes sense.


Password Protecting App in Development - El Forum - 09-10-2010

[eluser]Buso[/eluser]
If you have a base controller, you can make a simple check inside its constructor like:

Code:
if( $this->uri->uri_string()!='/' AND ! is_role('admin')) {
  redirect();
}

Of course you will need to create the is_role function or something similar, and authenticate through a login panel or something. You could also make an IP check, and if it is different to yours, redirect to the home.

Code:
$my_ip = 'your.ip.goes.here';
if( $this->uri->uri_string()!='/' AND ! $this->input->ip_address()!=$my_ip) {
  redirect();
}

Or set a cookie with a secret value