DISQUS

DISQUS Hello! Md Emran Hasan (phpfour) is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Md Emran Hasan (phpfour)

This is Emran Hasan's blog for PHP, CSS, XHTML, JavaScript, Web 2.0, AJAX, Usability, and Web Standards related views, ideas, and sharing.
Jump to original thread »
Author

Htpasswd protection library for Code Igniter

Started by Md Emran Hasan (phpfour) · 9 months ago

This is a library designed to run with Code Igniter that allows the application to protect any folder in the webserver using the htpasswd method of Apache. It can also group the users and create group based permission on the folders. The use is very simple: you need to define an array of ... Continue reading »

12 comments

  • Thats a great article Emran. Keep it up. But can you rename the clas like something

    ServiceAuthentication

    or

    AuthHtpasswd
  • Done. Thanks for the suggestion :)
  • It's a nice thing I think but I've no time to see it.

    Thanks! :)
  • This example and article is very nice. However i get a problem when i run the code in the line $this->AuthHtpasswd->protect(.....)
    but i check the $this->load->library('AuthHtpasswd');
    is ok . But i do not know why it gets error. However to check your example i try it different way $auth=new AuthHtpasswd();
    and it works. but i know it must be work , in the way done. Can u tell me what type mistake may be i have done to run your script.
    Thanks
    http://saidur.wordpress.com
  • Hello Mr. Saidur,

    Thanks for your reply. I've just found the problem - while Code Igniter loads any library, it puts the name in small case. So, instead of calling $this->AuthHtpasswd->protect(..), please call $this->authhtpasswd->protect(..).

    I have made change to the code and re-uploaded it.

    Thanks
  • hi bro,
    nice to see you continuing your blog :)

    just a small tip -
    "class Protect extends Controller"
    as i can see your "Protect" class has extended "Controller"

    so you should name like this -
    "ProtectedController"
    or "SecureController"
    or "AuthenticateController"

    hope that will be in help.

    best wishes,
  • oh by the way,
    you don't need to put @author tag with every function :)

    instead try once on the top class level.
  • Hello Hasan,

    Thanks for your suggestions ! I will keep the @author thing in mind for future use.

    Regarding the controller name, Code Igniter requires writing controller name without the Controller suffix, as this becomes a part of the url:

    http://www.domain.com/protect/index

    Thanks for your comments, its been long you've visited my blog :)

    Cheers!
  • hi emran bhai,
    thank you for mentioning about the Code Ignitor specific convention. i didn't know that, how is going everything ? how is going study and new company ???

    hope will c you soon.

    best wishes,
  • Hasan,

    Study is almost done...final exams of the last sems remaining and then the internship.

    Company is doing well by the grace of Almighty. We're working with cool, new stuffs and discovering new things every now & then. And our 2nd recruitment is going on, possibly new team will start from Oct 1.

    Will come to swi next week, will meet then. Take care!
  • I am creating a subscription site for my client, on successful login authentication user will access the subscribed page. Here the user gets authenticated form /subscribe/login.php and accessing page is in /accessfolder/page.html. Now how to check the user is authenticated (using login.php). dont want to use any auth.php or script. it should be happen using the .htaccess or .htpasswd
  • @Sanjeev: This library will actually check user authenticity using .htaccess method, so login.php would not be needed.

    After a successful subscription through your registration form OR admin panel, take an array of all the valid users from DB and use the class to create the .htaccess file for the folder.

    Also, when a subscription is over, OR an user is deleted from admin panel, do the same to update the .htacess file.

    Hope this helps.

Add New Comment

Returning? Login