Custom URL for each user in PHP(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
基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01