| | |||||
| ||||||||
| CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Sep 2005 Location: At Home
Posts: 881
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Giving a user access to a password protected folder Is it possible for me to give access to a password protected directory to a certain member and setup their account automatically? If so how? I tried but can't find anything. Thank you
__________________ |
| |
| | #2 (permalink) |
| CEO at Syack Inc. ![]() Join Date: Jun 2005 Location: Pennsylvania
Posts: 1,879
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | use the .htaccess file... then write a script to automatically edit it
__________________ Poker News, articles, discussion Syack - Shop.. Local Two great events started with apples. The one that fell on Neuton's head and the one that Steve Jobs bite into. |
| |
| | #4 (permalink) |
| If only you knew... Join Date: Oct 2005 Location: Inside your head...
Posts: 990
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | This isn't truelly, in iteslf "automatically", as you put it. But, you said you know how to write to the .htpasswd file (and this script assumes you would be doing so with PHP ). This shows a form to be filled-out (request for username and password), and auto-adds it to .htpasswd file after it encrypts the password (.htaccess usernames are not encrypted, only passwords are). You can alter it to get the variables passed by means other than the form, should you need to do so. This script only adds new entries, and does not let you alter current ones. If you need that added functionality, just let me know ![]() ".htaccess" file: Code: AuthUserFile /path/to/your/hidden/password/files/.htpasswd AuthName "Private Directory" AuthType Basic require valid-user PHP Code: 1) Move your .htpasswd file to a sub-root folder (ie: one that is not directly web accessable). -OR- 2) Rename your .htpasswd file to something other than ".htpasswd"...As long as you put the name correctly in the .htaccess file itself, it will read it. Name it something odd and hard to guess, and create an odd extention (example: ValidMembers.list - not very creative, think of your own...just an example ). Instead of your .htaccess having the obvious:AuthUserFile /path/to/your/protected/area/.htpasswd it would have: AuthUserFile /path/to/your/protected/area/ValidMembers.list Need any more help, or don't understand anything there...just give me a yell here or in PM Disclaimer: I acknowledge that there are more effective and clean ways to do this. But, I am not trying to write the above code for commercial use. Those finding errors, please let me know. Those wishing to educate me on my PHP coding, are also gladly asked to do so. However, those wishing to just nag or make themselves look smarter.....Go code something yourself...Preferably with PHP's ever-so-useful die() command ![]() ------------------------------------------------------------------ Update to my would-make-SecondVersion-think-I'm-stupid code:The following allows you to edit the file directly Not the best code in the world, but think it will do what you are seeking, if you wish to ad users by hand. To add them via another script, remove the form elements and just create a script to post to this.PHP Code:
__________________ --- The greatest truths ever told, and the greatest lies ever told, all consist of exactly the same three words: "I LOVE YOU" --- The best say little, only say what is important.....then they shut up and sit down.
Last edited by maximum; 10-19-2006 at 03:57 PM.
|
| |
| | THREAD STARTER #5 (permalink) |
| NamePros Regular Join Date: Sep 2005 Location: At Home
Posts: 881
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | thanks alot for your script but I think there is a problem with the encryption. check it out at http://www.asgsoft.net/test/
__________________ |
| |
| | #6 (permalink) |
| If only you knew... Join Date: Oct 2005 Location: Inside your head...
Posts: 990
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Sorry. It isn't the encryption, which is standard. It is a matter of those hidden characters (line-feeds/carriage-returns that create each of them on a new line). Those little hidden characters are being read as if they were supposed to be part of the user-pass combo when the server reads the file to prompt for logins. I will let you know when fix that.
__________________ --- The greatest truths ever told, and the greatest lies ever told, all consist of exactly the same three words: "I LOVE YOU" --- The best say little, only say what is important.....then they shut up and sit down. |
| |
| | #8 (permalink) |
| If only you knew... Join Date: Oct 2005 Location: Inside your head...
Posts: 990
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | The both cleaned-up and corrected version of that code, rewritten by NamePro's resident PHP guru SecondVersion. Hope this solves that issue for you. Thank You, SecondVersion PHP Code:
__________________ --- The greatest truths ever told, and the greatest lies ever told, all consist of exactly the same three words: "I LOVE YOU" --- The best say little, only say what is important.....then they shut up and sit down. |
| |