Jump to content
xisto Community
Sign in to follow this  
Albus Dumbledore

How To Protect A Directory From Being Viewed without admin username and password

Recommended Posts

Well i ran across this script awhile back, and i am tired of storing it on my computer, so i am going to post it here and whenever i need it i will come here and get it :) hopefully

Anyways, it is a verry simple process just copy and paste this

if (($user) && ($passwort))
# get url

$url = $DOCUMENT_ROOT . dirname($PHP_SELF) . "/.htpasswd";

# make .htaccess and .htpasswd

$htaccess_txt = "AuthType Basic" . "\n";
$htaccess_txt .= "AuthName \"protected area\"" . "\n";
$htaccess_txt .= "AuthUserFile $url" . "\n";
$htaccess_txt .= "require valid-user" . "\n";

$htpasswd_txt .= "$user:".crypt($passwort,CRYPT_STD_DES)."\n";

# save files

$htaccess= fopen(".htaccess", "w");
$htpasswd= fopen(".htpasswd", "w");

fputs($htaccess, $htaccess_txt);
fputs($htpasswd, $htpasswd_txt);

# output

die ("OK!<HR>" . nl2br($htaccess_txt) . "<HR>" . nl2br($htpasswd_txt));


<HTML><HEAD><TITLE> MAKE .htaccess + .htpasswd </TITLE></HEAD>
<p>Username: <INPUT TYPE="TEXT" NAME="user"></p>
<p>Passwort: <INPUT TYPE="TEXT" NAME="passwort"></p>
<p><INPUT TYPE="submit" VALUE="make"></p>

into Notepad, or your local HTML editor, and save it as password.php (or whatever you want lol)

then upload it to the directory you want to protect, for say your /image directory..

CHMOD it to 777

then go to http://ww38.yoursite.com/password.php and enter the admin username, and admin password then hit the submit button (or whatever the button is called)

then it shall be created! easy enough?

Share this post

Link to post
Share on other sites

I havent tried, but im sure its a good one..And also, for beginners, you can hide your directories by creating an empty (or full, what you want...) index.html file..But by a offline browser, professionals can figure out the directories. (and i guess, if u have no link to these file which u want to hide, they cant know.)

Share this post

Link to post
Share on other sites

but what if you want to protect multiple directories? does this apply to the subdirectories under the directory which the file is placed? i would probably use it for my hosting account here at trap...speaking of that... gonna get more points.... i'm running out of days, and i still don't have a connection at home. tsk. i don't know why my parents keep on restricting me when it comes to the internet.

Share this post

Link to post
Share on other sites

Cpanel has a built in function that allows you to set user passwords for each directory, if you want. It can also prevent someone viewing the contents of a directory without an index page.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.