gpt4 book ai didi

php - 为新站点用户自动创建自定义页面(或 URL)- PHP

转载 作者:行者123 更新时间:2023-11-29 03:01:17 25 4
gpt4 key购买 nike

我的网站,就其最基本的形式而言,是一个针对特定类型个人的网络站点。当一个人注册时,我想创建一个自定义页面(或至少是一个图像/外观)来显示他们的个人资料。目前,我使用 PHP $_GET 参数来确定当用户导航到站点上的相应脚本时要显示的配置文件。

为了更好的搜索引擎优化,我希望每个用户都有自己独特的链接;例如,FaceBook 允许其用户拥有一个他们可以链接的自定义 URL。我如何为每个注册的新用户在目录中自动生成一个页面,并在用户更新他/她的详细信息时让该页面自动更新?我知道 .htaccess 可能有一个潜在的过程,使用用户的姓名/职务/等从数据库中提取他们的详细信息,但将其显示为唯一的 URL。

任何人都可以提供建议或实现示例吗?我感谢所有帮助!

附言我想,一旦上述功能得到解决,根据用户位置(即按州)对文件进行排序应该不会那么困难。理想情况下,我想要这样的目录结构 ../users/state/user_name,其中 state 是用户的位置,user_name 是他们的唯一名称。再次感谢!

最佳答案

apache 的 .htaccess 几乎没有工作 - 大部分逻辑都在 php 本身中。 Apache 只是将每个请求重定向到选定的脚本文件。

我假设您使用 apache wid mod_rewrite。如果是这种情况,您应该将其添加到 .htaccess 文件中:

# check if mod_rewrite is present
<IfModule mod_rewrite.c>
#turns it on
RewriteEngine on

#if the requested url isn't a file or a dir
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#process index.php, no matter what was in the url
RewriteRule ^ index.php [L]
</IfModule>

(注意 .htaccess 还必须具有覆盖 apache 的当前设置的权限)

在 index.php 中你可以检查哪些 url 被隔离并处理信息

$whatTheUserRequested=$_SERVER['REQUEST_URI'];
$parameterArray=explode('/', $whatTheUserRequested);

//check the first param.
switch($parameterArray[1])
{
//if it was something like "thesite.com/main/fsadf/hgfdsgsdf/...."
case "main":
include "mainPage.php";
//....or do something else
break;

//if it was something like "thesite.com/login/asdfe/xxxx/...."
case "login":
include "loginPage.php";
//....or do something else
break;

default:
//here you MUST check if $parameterArray[1] is a username
if(check in db if $parameterArray[1] is user)
{
include "userPage.php";
}
else
{
include "pageNotFound.html"
};
}

您还可以检查包含的 php 中的第三个或第四个参数,以处理像“mysite.com/johnny95/edit”这样的 url

关于php - 为新站点用户自动创建自定义页面(或 URL)- PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23275736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com