views:

310

answers:

1

Is it possible to have a website where each user gets their own URL like: www.thewebsite.com/myusername

I want each user site to be the same, the only reason the name matters is if a person visiting the site signs up, they get their own custom url, but the person they signed up under is kept track of as their "Parent".

So if I go to www.thewebsite.com/phil and sign up as David, then my site becomes www.thewebsite.com/david but Phil is kept track of in my user record. (i.e. is there a way for me to know which url they visited the site under)

So, really that's 2 questions:

1) How do I make custom urls per user 2) How do I know which url a new user visited from

I'm pretty brand new to PHP so keep that in mind.

+2  A: 

You can implement this using the apache mod_rewrite.

Make a rewrite rule for something like:

^/users/($1)    /users.php?userid=$1

In user.php file read the userid parameter, and return the page corresponding to given user.

As for racking from which user someone registered/logged-in to your site, you can keep a session value, such as the referencing userid, and when the new user registers, write to your db who referred him to your site.

Am
Is it possible to do this without access to mod_rewrite?As far as the mod_rewrite thing goes, I'm guessing that the URL just shows to the user as /users/myuser but still displays to my program as /users.php?userid=myuserIs this correct?
Pselus
"As far as the mod_rewrite thing goes, I'm guessing that the URL just shows to the user as /users/myuser but still displays to my program as /users.php?userid=myuser Is this correct?"Yes, that's right.
lemon