DISQUS

Md Emran Hasan (phpfour): Htpasswd protection library for Code Igniter

  • Hasin Hayder · 2 years ago
    Thats a great article Emran. Keep it up. But can you rename the clas like something

    ServiceAuthentication

    or

    AuthHtpasswd
  • Md Emran Hasan (phpfour) · 2 years ago
    Done. Thanks for the suggestion :)
  • Jahed · 2 years ago
    It's a nice thing I think but I've no time to see it.

    Thanks! :)
  • Saidur Rahman · 2 years ago
    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
  • Md Emran Hasan (phpfour) · 2 years ago
    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
  • nhm tanveer hossain khan (hasa · 2 years ago
    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,
  • nhm tanveer hossain khan (hasa · 2 years ago
    oh by the way,
    you don't need to put @author tag with every function :)

    instead try once on the top class level.
  • Md Emran Hasan (phpfour) · 2 years ago
    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!
  • nhm tanveer hossain khan (hasa · 2 years ago
    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,
  • Md Emran Hasan (phpfour) · 2 years ago
    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!
  • Sanjeev · 1 year ago
    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
  • Md Emran Hasan (phpfour) · 1 year ago
    @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.