开发者

Custom URL for each user in PHP

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 b开发者_开发知识库ecomes 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜