【发布时间】:2020-08-15 19:34:45
【问题描述】:
我想用常规文件编写一个项目。索引文件有一个 php 代码,其中在 URL 中打开的所有文件都是开关。比如:
index.php
<?php
if(isset($_GET['page'])){
$current_page = isset($_GET['page']) ? $_GET['page'] : '';
}else{
$current_page = 'index';
}
$result = str_replace(".php","", $current_page);
switch($result){
case 'welcome':
include('sources/welcome.php');
break;
case 'index':
include('sources/index.php');
break;
case 'profile':
// Here is the problem. I want to make Facebook style user profile system
// But the switch can not see profile username because it is working just for page names not usernames
break;
}
?>
与 index.php 文件中的代码一样,我使用开关调用页面。但是当用户打开个人资料页面时,一切都会改变。因为我想让会员的个人资料页面就像 Facebook 一样。赞http://www.mywebproject.com/username
我创建的 htaccess 在这里:
.htaccess
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
RewriteRule (?:^|/)([\w-]+)/?$ profile.php?username=$1 [L,QSA]
我的问题是这样的。如何在 switch 中使用他们的用户名调用成员的个人资料。
【问题讨论】:
-
profile不在$thePage中