Page 1 of 1

Unable to Create/Write File due to Permissions

Posted: Mon Aug 23, 2010 10:06 pm
by webbiz
Hello. I'm an absolute PHP newbie. Just to get that out of the way. :)

On my site, I have a file called .htaccess. When someone drops into my site at the URL where this file exists, it pops up a dialog box that asks a question (I use the AuthName for this) for the user to look up the answer to discover the password.

I want to change this question everyday. So I wrote a PHP script that has the questions in an array and selects the questions based on what day it is. So far, so good.

My problem, however, is that I am unable to write to this file. I get a Permission Denied type error message. So I tried to use the Chmod() to change the file to 0777. No good. It comes back "Operation not permitted..." and the line number of the Chmod().

I'm just not sure where to go from here. I want to write over (not append) this file each time the script is run. What am I doing wrong?

Thanks.
Webbiz

Re: Unable to Create/Write File due to Permissions

Posted: Tue Aug 24, 2010 1:21 am
by Christopher
How did you create the .htaccess file in the first place? It probably has the user set to your login/FTP account -- not the webserver. PHP runs as the webserver user, so it cannot change the permissions (which is a good thing). You can change the user for .htaccess to be the same as the webserver. However, it might be better to write you own authentication code rather than using HTTP authentication.

Re: Unable to Create/Write File due to Permissions

Posted: Tue Aug 24, 2010 1:46 am
by Benjamin
webbiz wrote:So I tried to use the Chmod() to change the file to 0777. No good. It comes back "Operation not permitted..." and the line number of the Chmod().
Have you tried changing the permissions via FTP or SSH?
Christopher wrote:However, it might be better to write you own authentication code rather than using HTTP authentication.
Chris is right, the way you are trying to do this is not correct because there are better and more secure ways to accomplish the same functionality.

Re: Unable to Create/Write File due to Permissions

Posted: Tue Aug 24, 2010 6:17 pm
by webbiz
What better solutions are there? I'm open to direction on this.

As long as I can get it to where if someone tries to access this directory they have to answer correctly a question asked, that would fit the bill.

:)
Webbiz

Re: Unable to Create/Write File due to Permissions

Posted: Sat Sep 04, 2010 11:56 pm
by jmgek
Try 755 I think in Cmod

Re: Unable to Create/Write File due to Permissions

Posted: Sun Sep 12, 2010 6:20 am
by kaisellgren
I ask for FTP credentials just as I ask for SQL credentials. Things are more likely to work using the user's FTP account. Try that.