user3577343
user3577343

Reputation: 11

Password protect a view

I have a PHP page that I've defined as a view in the controller and was wondering how I'd go about password protecting this page? I couldn't get it to work using .htaccess (I could password protect the whole CodeIgniter installation folder but not individual folders or views).

The PHP page I want to password protect is inside an admin folder which is inside the views folder.

Upvotes: 1

Views: 607

Answers (1)

Sirius_Black
Sirius_Black

Reputation: 471

first, on the view folder make a .htaccess file and a .htpasswd file

on .htaccess put this

<files page.php>
AuthType Basic  
AuthName "Restrict Access"
AuthUserFile /home/db_name/dir/dir/.htpasswd
Require user your_name
</files>

where it has /dir/ change for your dir's names where it has your_name change for your login name

now go to this site

http://www.web2generators.com/apache/htpasswd_generator

to generate a .htpasswd
there you will put your user like
user: user
pass: user

it will be something like this

user:$apr1$sip1ow0t$taXqU/KmZL7bH/rXqqZvS0

put that on your .htpasswd file

now the page view.php is protect
if you want to protect the view folder put

<Directory /dir/dir/view>
code
</Directory>

Upvotes: 1

Related Questions