Welcome Guest, Not a member yet? Register   Sign In
Is there a library or helper that can help me block access to certain parts of my site?
#1

[eluser]Unknown[/eluser]
Hello All,

I was wondering if CI had some tools that could solve my problem easily before I tried a bunch of other things. I want to password protect a certain area of my site. For example, I want to make sure that no one can access http://example.com/secret (and any URL's that contain this) without being asked for a password. If they can't provide the password, they would be denied access.

I've heard about something called .htaccess and .htpasswd, but was wondering if there was a simpler solution from CI before I started with those, because they seem a little complicated IMO.

Thanks for any help!
#2

[eluser]InsiteFX[/eluser]
You could create a method for restricting access to any parts of your application.

Code:
public function restrict($access)
{
    // your code here to restrict access depending on $access
}
#3

[eluser]Unknown[/eluser]
Hello InsiteFX,

Thanks for your reply. I'm not quite sure I follow. What should the variable $access contain if I'm trying to restrict/block access based on a password?

What I was trying to achieve by making http://example.com/secret password protected was to make it such that if they don't give me the right password as soon as they get to this page, the controller called "Secret" wouldn't load at all (effectively making the page useless to anyone without the password). Is that possible with anything CI already has?

#4

[eluser]InsiteFX[/eluser]
$access - would be like an auth group or a user, it could also be an access level.

You could check for this in the Constructor and restrict that controller.
#5

[eluser]Alucemet[/eluser]
There are a number of authentication (auth) libraries for CodeIgniter. A simple search on Google for "CodeIgniter auth" should list a few choices.




Theme © iAndrew 2016 - Forum software by © MyBB