Connect with Expertise | Find Experts, Get Answers, Share Insights

writting .htaccess files

yawnmoth
 
Posts: n/a
#1: Jul 16 '05
i'm trying to write a php script that will password protect some
random directory by creating a .htaccess file, and a password file to
accompany the .htaccess file, and it isn't working... specifically, i
can't enter the newly created directory with a username of test, and a
password of test, which is what i am trying to do.

also, i'm testing this script out on a remote server, and... after
this script runs, i can't delete any of the files it produces...
specifically, i get this error:

rm: cannot unlink `.htaccess': Permission denied

i was told that the problem was that the owner of the file was
incorrect, but... i've made other scripts that create files, and
haven't had any problems deleting those files... so why would i have
a problem deleting these files?

any help would be appreciated! here's the script:

<?
$user = "test";
$pass = "test";

system("mkdir tester");

$filename = "./tester/.htaccess";

$fp = fopen($filename, "w");
fputs($fp,"AuthUserFile ./tester/.tester\n");
fputs($fp,"AuthGroupFile /dev/null\n");
fputs($fp,"AuthName EnterPassword\n");
fputs($fp,"AuthType Basic\n\n");
fputs($fp,"require user wsabstract");
fclose($fp);

$filename = "./tester/.tester";

$fp = fopen($filename, "w");
fputs($fp,$user . ":" . crypt($pass,substr($pass,0,2)));
fclose($fp);
?>

MeerKat
 
Posts: n/a
#2: Jul 16 '05

re: writting .htaccess files


yawnmoth wrote:
[color=blue]
> i'm trying to write a php script that will password protect some
> random directory by creating a .htaccess file, and a password file to
> accompany the .htaccess file, and it isn't working... specifically, i
> can't enter the newly created directory with a username of test, and a
> password of test, which is what i am trying to do.[/color]

You've said:
fputs($fp,"require user wsabstract");
when I believe that should be:
fputs($fp,"require user test");
[color=blue]
> also, i'm testing this script out on a remote server, and... after
> this script runs, i can't delete any of the files it produces...
> specifically, i get this error:
>
> rm: cannot unlink `.htaccess': Permission denied
>
> i was told that the problem was that the owner of the file was
> incorrect, but... i've made other scripts that create files, and
> haven't had any problems deleting those files... so why would i have
> a problem deleting these files?[/color]

Don't know about this one. Try checking the permissions on the directory
in which the file is kept - maybe there is no write permission on that
(although then you wouldn't have been able to write the .htaccess file).

Try a system call:
system('rm ./tester/.htaccess -f');
(the -f is 'force', not sure if this will help).

MK.

[color=blue]
> any help would be appreciated! here's the script:
>
> <?
> $user = "test";
> $pass = "test";
>
> system("mkdir tester");
>
> $filename = "./tester/.htaccess";
>
> $fp = fopen($filename, "w");
> fputs($fp,"AuthUserFile ./tester/.tester\n");
> fputs($fp,"AuthGroupFile /dev/null\n");
> fputs($fp,"AuthName EnterPassword\n");
> fputs($fp,"AuthType Basic\n\n");
> fputs($fp,"require user wsabstract");
> fclose($fp);
>
> $filename = "./tester/.tester";
>
> $fp = fopen($filename, "w");
> fputs($fp,$user . ":" . crypt($pass,substr($pass,0,2)));
> fclose($fp);
> ?>[/color]

--
MeerKat

Closed Thread