473,415 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,415 software developers and data experts.

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,"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);
?>
Jul 16 '05 #1
1 7678
yawnmoth wrote:
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.
You've said:
fputs($fp,"require user wsabstract");
when I believe that should be:
fputs($fp,"require user test");
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?
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.

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

Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Els | last post by:
***newbie question*** Hi, I am trying to make my server (Apache) parse .html files as .php. I found this line of code: ForceType application/x-httpd-php placed it in an .htaccess file and...
5
by: Vinicius | last post by:
Hi, I have this script to list files in the same directory; <? $dir=opendir("."); readdir($dir); readdir($dir); while ($conteudo = readdir($dir)) { echo "<a...
0
by: Jack Hambabo | last post by:
Hi, I'm searching for a php script that can find out whether the current user (I know _SERVER will give me the name for non-cgi php) has the right to view a specific file. My dream is that I...
4
by: Stefan Bellon | last post by:
Hi all! I want to parse the contents of an .htaccess file from within PHP. The contents of the .htaccess file looks like this: <Files foobar.tar.gz> AuthType Basic AuthUserFile /foobar...
1
by: nickyeng | last post by:
I have checked this info from apache website, and i confused with it. Procteing System files it said: To run a really tight ship, you'll want to stop users from setting up .htaccess files...
0
by: asherwolf | last post by:
Hi, I'm trying to do something I think is pretty neat, but I've just about pulled my hair out by the behavior of my server. I'm hosting on GoDaddy, using a subdomain (www.mywebpage.com maps to...
2
by: jaanus | last post by:
Here we go... What I have been trying to do is to forward all http requests containing /cms/ to http://cms.mydomain.com/ example1: http://host1.mydomain.com/cms/init.php would be parsed from...
5
by: Kurda Yon | last post by:
Hi, in the home directory I put .htaccess with "register_globals 0". Obviously, all php-files from this directory will not take variables from the address line. But, as far as I understand, the...
8
by: Geoff Cox | last post by:
Hello, Using .htaccess and a linux server is it possible to give group access to a person so that he/she can access files in several different folders? If yes, how is this done?! Cheers
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.