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
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01