Protected directory using .htaccess & .htpasswd under Apache Server

To protect a directory under Apache Web Server we need to use .htaccess & .htpasswd. So here i describe how an we do it :

Step 1 :  Create new Directory or We can use existing directory suppose we have a directory as “dev”

Step 2:  Create .htaccess or open existing .htaccess by editor under dev directory and put this text:

 Step 3 : Then we need to create .htpasswd file in /root or somewhere and must be accessible and open with editor put this text:

So heres the big question how can we create encrypted password  for .htpasswd. We can do this using a command like:

so it will create an encrypted password against user_name and update into .htpasswd file. More information about htpasswd command is here Otherwise  you can find many online tools create password like:


Here i mention some important notes & troubleshooting topics:

  • .htpasswd Format: username:encrypted_password
  • case sensitive username i mean user_name, user-name, User_Name totally different
  • Location of .htpasswd its depend on you but recommend outside of your web documents   accessible area.

Troubleshooting Notes:



  • Make sure .htpasswd path is correct i mean in .htaccess  file AuthUserFile is full path of .htpasswd
  • Make sure about permission & you can change like those command
  • It doesn’t seem to be Working – Error 404? so you need to below line top of the .htaccess file


So i hope it will work as like you want.

Codeigniter htaccess for mac, linux and godaddy hosting server

From codeigniter if you want remove index.php from url first you need to edit config.php file from config directory like

and then you need to create htaccess file with mod_rewrite module enable. Edit htaccess file look like :

Mac OSX Environment:

Linux OS Environment :

Godaddy Hosting Server:

Thats now you will see your site url without index.php :)

MySQL query with if else condition

MySql query with if-else condition:

Here’s the statement:


Using wkhtmltopdf and ImageMagick make pdf and image

Setup wkhtmltopdf in ubuntu:

Setup ImageMagick

create pdf :

create image :

Codeigniter CSRF with AJAX

Thats the very important issue when you enable csrf protection for security reason in codeigniter framework based project then you must face some problem ajax related. So here’s the code how to resolve it :

How to Create Select field using Zend Framework2 Form

First I  Create Form Class name CategoryForm.php in Form directory. Source Code

In Controller i add this lines:

In view file i add this line :


Codeigniter pagination style with twitter bootstrap pagination

I want to style my pagination view with twitter bootstrap style and i used codeigniter php framework and twitter bootstrap. First i create controller name is front  and action is news.

Then in view page write this code:

After that my pagination look like twitter bootstrap pagination components.

Get date after 1 week from current date or specific date

In my project i need find after 7 days or 1 week later date from current date or specific date.So this purpose i need to get after 7 days date form current or specific date.

Here’s my php code :