Password Protected File

liunx

Guest
I need a way to password protect a php file, I know thta I can password protect a directory, but nort what I want to do, my last site UI could do tghis<br /><br /><br />Thanks<!--content-->
You can either,<br /><br />incorporate the password into the php script (so that it does start that script, but only completes it if you provide the correct password).<br /><br />Or<br /><br />You could edit the .htaccess file and add a password requirement in there for that file.<br /><br />Personally, I'd go for option 1.<!--content-->
<!--quoteo(post=158441:date=Dec 11 2005, 02:57 AM:name=TCH-Andy)--><div class='quotetop'>QUOTE(TCH-Andy @ Dec 11 2005, 02:57 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=158441"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->You can either,<br /><br />incorporate the password into the php script (so that it does start that script, but only completes it if you provide the correct password).<br /><br />Or<br /><br />You could edit the .htaccess file and add a password requirement in there for that file.<br /><br />Personally, I'd go for option 1.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />I am just learning PHP, so not familar with either option<!--content-->
In that case, open your .htaccess file, and add<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->AuthName "Restricted Area" <br />AuthType Basic <br />AuthUserFile /home/myusername/.htpasswd <br />AuthGroupFile /dev/null <br /><Files protect1.php><br />require valid-user<br /></Files><!--c2--></div><!--ec2--><br />where myusername is your cpanel username and<br />protect1.php is the file to be protected<br /><br />You will then need to create a file .htpasswd in your top directory<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->user:pass<!--c2--></div><!--ec2--><br />but the password will need to be encrypted. The easiest way may be to password protect a directory then get the encrypted password from the .htpasswd file.<!--content-->
 
Back
Top