Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

Hi I am looking for a simple php script that will generate (create .htaccess and .htpassword) to protect a folder

as simple as that ! ex: protect.php?username=admin&password=admin and it will create automatially the .htaccess and .htpasswd that protects the folder with user admin/amin

Regards

share|improve this question
1  
Does the Apache user have write permissions in those directories? otherwise it won't be able to create the files; PHP scripts get executed with the Apache user's permissions. Also, have you checked that your Apache configuration allows .htaccess creation in those directories? check your AllowOverride configuration. Finally, it's a security risk to leave the .htpasswd file in a web-accessible directory, so consider the fact that those will need to go elsewhere. – Roadmaster Nov 24 '10 at 22:55
    
A better solution might be to have a PHP script dynamically create login prompts, instead of making it a meta tool to create files to make Apache throw up these prompts. It's all just HTTP headers being send back and forth, these can be generated by other means than .htaccess files. Have you looked into this option, or do you specifically need to generate .htaccess files? – deceze Nov 24 '10 at 23:48
    
You might consider using POST instead of GET for this, just because generally GET shouldn't cause side effects. :) – echo Nov 25 '10 at 0:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.