473,788 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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);
?>
Jul 16 '05 #1
1 7698
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,"requ ire user wsabstract");
when I believe that should be:
fputs($fp,"requ ire 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,"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

Jul 16 '05 #2

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

Similar topics

6
5183
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 uploaded it to the directory I wanted it to work. And it worked; my .html files are all parsed as .php.
5
5270
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 href=./$conteudo>$conteudo</a><br>";
0
2003
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 just need a short php script that just asks the webserver what the rights are. That seems a reasonable wish to me. If this is however not possible than I'd like a script that can
4
2813
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 AuthName "Foobar" <Limit GET>
1
4898
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 which can override security features you've configured. Here's one way to do it. In the server configuration file, put
0
11289
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 /mywebpage), running Apache 1.3.33, and PHP 4.3.11. The goal is to use PHP to install an .htaccess file in a folder to forbid PHP files from being accessed from outside the server. I have a working .htaccess file in one folder, and I have been...
2
9256
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 http://cms.mydomain.com/init.php (via ajax request) example2: <script src="http://host1.mydomain.com/cms/example.js" in <html><head> would be parsed from http://cms.mydomain.com/example.js physically there are no cms directories in...
5
2460
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 .htaccess files influences on all files in the subdirectories so that they also cannot take the variables from the address line. Should it be like that?
8
3467
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
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.