purplespider Posted March 19, 2004 Posted March 19, 2004 Is it possible to use .htaccess to protect a few dir's or pages and depending on the username it send them to a certain page? If not, what would be the easiest way of doing this? Cheers James Quote
DarqFlare Posted March 19, 2004 Posted March 19, 2004 Username? You mean a pass-protected directory? I'm not entirely sure how to manipulate HTACCESS to deal with username-specific content... MikeJ might know. Quote
TCH-Rob Posted March 19, 2004 Posted March 19, 2004 Try Looking here; http://www.faqts.com/knowledge_base/view.phtml/aid/8966 Redirect by UserNameWhen a user logs in the REMOTE_USER environment variable is set and can be read from htaccess. You can use this to redirect users to sub-directories based on their username. RewriteCond %{REMOTE_USER} !^$ [NC]RewriteRule .*index\.html$ /users/%{REMOTE_USER} Quote
purplespider Posted March 19, 2004 Author Posted March 19, 2004 Cheers Rob, that looks exactly what I'm after, but I'm not 100% sure how to use it. I've setup a directory *****/users under which there is a seperate folder for each user with the same name as that user. I've protected /users in Cpanel and added the usernames and passwords, now I presume I have to add something to the .htaccess file in /users but I'm not sure what. Any idea? Cheers James Quote
TCH-Rob Posted March 19, 2004 Posted March 19, 2004 James, I will have to play with it. I havent even seen the script before I looked for it last night. I will play with it and see what I can come up with. Quote
DarqFlare Posted March 19, 2004 Posted March 19, 2004 Hey Rob, nice job... that's good to know, even though I'm not sure I'd ever use it... Quote
TCH-Rob Posted March 19, 2004 Posted March 19, 2004 (edited) I havent gotten a chance to look into it too much yet but I will say that I dont think I would use it. It may be fine for a few users but if you ever got into the tens or hundreds or more it would be a pain to have to update it whenever a new person comes or someone goes. There are other options using PHP and other scripts that use a database to achieve the same results. I think it would be better to go that route if one has many users that need this feature. Just a few and this should be fine. Edited March 19, 2004 by TCH-Rob Quote
purplespider Posted March 19, 2004 Author Posted March 19, 2004 Oh ok then, I'm only going to have about 5 but I'll try find a PHP script to do it if you think that would be best. James Quote
TCH-Rob Posted March 19, 2004 Posted March 19, 2004 James, I have tried a few various incarnations of that .htaccess option. I can not get it to work properly, I get a page not found or a redirect to the list of folders with usernames. I encourage you to give it a go still if you want, maybe one of the Mikes has a better answer. I found this option by "googleing" redirect users based on username no quotes. There were other options with various scripts. You may want to have a go at that as well. Quote
purplespider Posted March 19, 2004 Author Posted March 19, 2004 I've searched all through the User authentication section of hotscripts.com and there are hundred of scripts to have lots of users able to login to a 'members area', but I can't find any which go to a different page depending on the user. Can anyone help me with this? Cheers James Quote
TCH-Rob Posted March 19, 2004 Posted March 19, 2004 Here is a js version http://forums.devarticles.com/archive/t-3012 A possible PHP version http://www.zend.com/zend/tut/authentication.php Quote
purplespider Posted March 20, 2004 Author Posted March 20, 2004 Hi Rob, yeh they work well apart from if someone knows the address of the page they can get to it directly without the username or password. Thats why I like the idea of the .htaccess thing. If you have a chance it would be cool if you could have a look at the .htaccess way of sending a user to their own page. If it looks too complicated then it doesn't matter, and thank you for all your help. James Quote
purplespider Posted March 20, 2004 Author Posted March 20, 2004 Oh, sorry, didn't see your post above. I'll look through google and see what i can find, thanks again for your help! James Quote
DarqFlare Posted March 20, 2004 Posted March 20, 2004 (edited) My best guess how I'd use it: >RewriteCond %{REMOTE_USER} ^user1$ [NC] RewriteRule ^.*index\.html$ /user1place RewriteCond %{REMOTE_USER} ^user2$ [NC] RewriteRule ^.*index\.html$ /user2place I wouldn't have it autoinsert the user myself, but if you can get that working, more power to you... Disclaimer: I'm not sure if this work, I haven't been able to test it. Edited March 20, 2004 by TCH-Robert Quote
TCH-Rob Posted March 20, 2004 Posted March 20, 2004 Hi Rob, yeh they work well apart from if someone knows the address of the page they can get to it directly without the username or password. So send them to /folder/name.htm and .htaccess the folder to only allow users to enter from password page. Like some larger sites do when the issue of deep linking was big, try and get to a deeper part of the site and it redirected you to a main page and you had to go from there. Quote
purplespider Posted March 21, 2004 Author Posted March 21, 2004 Cheers guys, so Robert, I'm not very familiar wi how to use the whole .htaccess thing, which .htaccess file should i put those lines in? Rob, never realised that was possilbe, is it relativly easy to do? Cheers James Quote
TCH-Rob Posted March 21, 2004 Posted March 21, 2004 Lets say your site was like this index - with link to pw protected members area - members folder -- member1 folder ------ member1 index -- member2 folder -- member3 folder If I went to member1 folder/member1 index I will still get the user pw prompt as it is in a folder under the main protected folder. Throw in a redirect on each page that makes them log in at the members link and you can control it pretty well. Get the authentication set up and working so it redirects, I will find you the code to force entry through a specific page. Quote
DarqFlare Posted March 21, 2004 Posted March 21, 2004 If you're going to use one master HTACCESS file, use the one in public_html Quote
TCH-Rob Posted March 21, 2004 Posted March 21, 2004 I havent tried it yet but look here www.phpsecurepages.com Quote
TCH-Rob Posted March 21, 2004 Posted March 21, 2004 (edited) Another option may be to have a form, where you have a text box and depending on what was typed in it, when submit was clicked, could be parsed to the URL. That folder would be pw protected for that user. I dont know how to parse a variable into a URL though. I was thinking something like this but it isnt quite right ><form action="<?php echo 'http://www.knifeandblade.com/members/users/, urlencode($user) '; ?>" method="get"> Your Name <input type=text name="user" size=20> <input type=submit value="Submit" /> </form> Maybe we can get some input from a PHP guru. Edited March 21, 2004 by TCH-Rob Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.