Jump to content

Recommended Posts

Posted

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

 

 

Thanks

Posted

You can either,

 

incorporate the password into the php script (so that it does start that script, but only completes it if you provide the correct password).

 

Or

 

You could edit the .htaccess file and add a password requirement in there for that file.

 

Personally, I'd go for option 1.

Posted
You can either,

 

incorporate the password into the php script (so that it does start that script, but only completes it if you provide the correct password).

 

Or

 

You could edit the .htaccess file and add a password requirement in there for that file.

 

Personally, I'd go for option 1.

 

I am just learning PHP, so not familar with either option

Posted

In that case, open your .htaccess file, and add

>AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /home/myusername/.htpasswd 
AuthGroupFile /dev/null 
<Files protect1.php>
require valid-user
</Files>

where myusername is your cpanel username and

protect1.php is the file to be protected

 

You will then need to create a file .htpasswd in your top directory

>user:pass

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...