writting .htaccess files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yawnmoth

    writting .htaccess files

    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,"Auth UserFile ./tester/.tester\n");
    fputs($fp,"Auth GroupFile /dev/null\n");
    fputs($fp,"Auth Name EnterPassword\n ");
    fputs($fp,"Auth Type Basic\n\n");
    fputs($fp,"requ ire user wsabstract");
    fclose($fp);

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

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

    #2
    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,"requ ire user wsabstract");
    when I believe that should be:
    fputs($fp,"requ ire 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,"Auth UserFile ./tester/.tester\n");
    > fputs($fp,"Auth GroupFile /dev/null\n");
    > fputs($fp,"Auth Name EnterPassword\n ");
    > fputs($fp,"Auth Type Basic\n\n");
    > fputs($fp,"requ ire user wsabstract");
    > fclose($fp);
    >
    > $filename = "./tester/.tester";
    >
    > $fp = fopen($filename , "w");
    > fputs($fp,$user . ":" . crypt($pass,sub str($pass,0,2)) );
    > fclose($fp);
    > ?>[/color]

    --
    MeerKat

    Comment

    Working...