Forum Moderators: coopster

Message Too Old, No Replies

Give user different site based on login

         

ltboy

9:24 am on May 29, 2005 (gmt 0)

10+ Year Member



I'm trying to set up a staging environment on my website where clients can see the progress on their web(site/page).

I was wondering if there was a way using php and/or other common apache modules to change the document root of a subdomain based on login data, collected either by HTTP authentication or just by an HTML form... Without editing apache2.conf or any other server-wide configuration file.

So for instance, joe visits stage.mydomain.com and is presented with a login request. once he logs in, stage.mydomain.com serves him the files contained in /web_designs/joes_site. But when jane logs in she is served the documents in /web_designs/janes_site while accessing the same url.

mcibor

7:00 pm on May 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



After validation

if it's not in url, then just

include("web_design/".$name."_site/index.php);

However if you want the name to appear in url then redirect

header("Location: web_design/".$name."_site/index.php");

Remember just, that $name cannot contain spaces, apostrophes, quotations, slashes, backslashes, etc.

Best regards
Michal Cibor

ltboy

2:08 am on May 30, 2005 (gmt 0)

10+ Year Member



Not quite what I'm looking for. I need to map all files in /web_designs/<user>_site to stage.mydomain.com. And actually this is in the wrong forum. The Apache Forum is probably where it needs to be.

coopster

2:55 pm on May 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Itboy.

I think you are in the right place, if I understand you correctly. Your wording seems a bit incorrect ("change the document root of a subdomain"), but your intention is described well enough to offer a possible solution.

Can we assume you are starting a session since you are authenticating a user? Well, as part of that authentication process, why not store the user's "project directory" as a column in the database? Push that variable into the session and upon successful authenitication, use that to build the url path through out the rest of the session.

ltboy

6:12 am on May 31, 2005 (gmt 0)

10+ Year Member



Heh. Again, you're misreading me. My goal is not to build a new url but instead to use the same url to serve a *completely different* web site based on who is viewing.
I have actually managed to get a not so great hack up using apache mod_rewrite and mod_auth.

[edited by: coopster at 10:30 am (utc) on May 31, 2005]
[edit reason] sorry, no urls (TOS [webmasterworld.com]) [/edit]

ltboy

8:39 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



Heh :) sorry bout that, musta missed that part...

coopster

9:56 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Apology accepted ;)

Where are you getting your dynamic data from? A database or a different directory? One way or another you must be pulling different data from somewhere based on the user though.

ltboy

2:33 am on Jun 8, 2005 (gmt 0)

10+ Year Member



I'm pulling data from a sub-directory of the /stage directory. Which, theoretically, should be fine. But it's not.

The .htaccess file for /stage(which is where stage.mydomain.com is served from):


AuthType Basic
AuthName "myDomain.com Staging Aread"
AuthUserFile "/path/to/passwords"
Require valid-user
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/$ /%{REMOTE_USER}/ [L]
RewriteRule ^(.*)$ /%{REMOTE_USER}/$1 [L]

This causes stage.mydomain.com to require http authentication, then serve documents from /stage/<user_name>. Note the duplicate entries. Theoretically, the second one should handle requests for both files and directories. However, without the first rule, if a directory is called that doesn't contain an index file, then the user's browser is redirected to stage.mydomain.com/<user_name>/directory/

The above alone, however, creates a loop, and allows one user to access another user's files by pointing their browser to stage.mydomain.com/other_user. So each user directory has to contain the following:


AuthType Basic
AuthName "myDomain.com Staging Area"
AuthUserFile "/path/to/passwords"
Require user <specific_username>
RewriteEngine Off

In my ideal scenario, I would be able to get the user information from a cookie or a PHP session instead of %{REMOTE_USER} and I wouldn't have to turn of the rewrite engine for each user directory. Also, there should be a better way of locking away the other user directories.