沃梦达 / 编程问答 / php问题 / 正文

PHP 中每个用户的自定义 URL

Custom URL for each user in PHP(PHP 中每个用户的自定义 URL)

本文介绍了PHP 中每个用户的自定义 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有一个网站,每个用户都有自己的 URL,例如:www.thewebsite.com/myusername

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".

因此,如果我访问 www.thewebsite.com/phil 并以 David 的身份注册,那么我的站点将变为 www.thewebsite.com/david,但 Phil 会在我的用户记录中进行跟踪.(即有没有办法让我知道他们访问了哪个网址下的网站)

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) 如何为每个用户制作自定义网址2) 我怎么知道新用户访问了哪个网址

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

我对 PHP 非常陌生,所以请记住这一点.

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

推荐答案

您可以使用 apache mod_rewrite.

You can implement this using the apache mod_rewrite.

为以下内容制定重写规则:

Make a rewrite rule for something like:

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

在user.php文件中读取userid参数,返回给定用户对应的页面.

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

至于从哪个用户注册/登录到您的站点,您可以保留会话值,例如引用用户 ID,并在新用户注册时写入您的数据库,将他推荐到您的站点.

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.

这篇关于PHP 中每个用户的自定义 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP 中每个用户的自定义 URL

基础教程推荐