D3_JMultiply
D3_JMultiply

Reputation: 1080

How Can I write to a file in a password protected directory?

I am creating an application form, here is what it does.

The php script takes the form information and writes a file named usr_firstname_lastname.txt

The directory is password protected using .htaccess and .thpasswd

.htaccess

# DO NOT REMOVE THIS LINE AND THE LINES BELOW PWPROTECTID:******
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/a9368227/public_html/applications/.htpasswd
Require user *****
# DO NOT REMOVE THIS LINE AND THE LINES ABOVE ******:PWPROTECTID

.htpasswd

*****:*********************************/

The '*' are obviously to prevent peope obtaining login info, however this is just to tell you what the the format is.

Now the point of password protecting the directory is so that only people with the password can see it, however I want it to be accessable. The only answers I can find on this are chmodding the directory to 711, I want everyone to be able to read the files, just need a password first, I don't want to block them.

I do not want to change the directory, I want all applications to be easily accessable by typing/applications at the end of the domain and entering a name. And for my purposes the directory must be password protected and chmodded to 755.

I'd think there would be a simpe answer on how to like pass a password and username to the directory, can anyone help?

If there is no way, I should be able to make a simple PHP script that asks for username and password and then lists the applications below, but I'd rather not...

Upvotes: 0

Views: 3125

Answers (3)

D3_JMultiply
D3_JMultiply

Reputation: 1080

I fixed it, I got it working on my own. PHP allowed me to copy the files into the protected directory, after creating them elsewhere. so I created them in a tmp folder and copied them, and deleted the original and it works, but I don't get why PHP wouldn't let me just write to it...

Upvotes: 0

Sjoerd
Sjoerd

Reputation: 75568

The .htaccess and .htpasswd file control access from the Internet directly to the directory. The chmod permissions control access from your PHP file to that directory in the filesystem. The two are not related. You can chmod it to 755 so that your PHP script can access it, and still put password protection on the directory if it is accessed directly from the Internet.

Upvotes: 3

safarov
safarov

Reputation: 7804

Here detailed explaination of how to do this http://www.javascriptkit.com/howto/htaccess3.shtml

P.S: but recommend to put secret information data files upper than public_html folder. For reach them write php script and make authorization for it as you wish

Upvotes: 1

Related Questions