3

I have a login form and I have designed my website in such a way that every user has his own dashboard.

After login, I check if

if($_POST['username']=="ryan")
{
redirect to ryan;s dashboard
}
if($_POST['username']=="jpn")
{
redirect to jpn;s dashboard
}

and so on for1500 usernames. Is it fine?

4

6 回答 6

4

Put the names and the dashboard URLs in a database. Make one query to look up the URL based on the posted name and redirect. You will have 4 lines of code instead of 6000.

于 2010-12-15T10:22:25.217 回答
1

No. If you really needed to choose between 1500 different routines, you should use something like the strategy pattern.

However, in your case, it's just the same routine (loading a user's dashboard) with different data. The procedures should be the same. How come you need different code to load each user's dashboard?

于 2010-12-15T10:22:35.707 回答
1

Think it's a problem in your design...things like this should never happen :)

You should use a script that fetches the user dashboard and only send the user id to that script!

于 2010-12-15T10:22:45.607 回答
1

if首先,我建议不要使用这样的switch语句,而不是那样做多个语句:

switch($_POST['username'])
{
   case "ryan" : //redirect to ryan;s dashboard
   case "jpn" : //redirect to jpn;s dashboard
}

其次,我根本不建议这样做来重定向到某人的仪表板。您应该有一个通用仪表板和一个包含用户名和仪表板详细信息的表格。然后使用用户名调用单个函数。

于 2010-12-15T10:23:24.803 回答
0

您应该重定向到 1 个仪表板。然后在仪表板中使用此值

login php ....
if($_POST['username'])
{
redirect to dashboard
}


dahsboard php 

welcome <?=$_POST['username']?>,
...
..
user spesific things..

如果你为 1000 个用户尝试你的代码,你会很累..

于 2010-12-15T10:23:18.290 回答
0

您可以做的是将用户名保存在会话变量中,并根据会话变量加载用户仪表板。假设您也请求密码,您应该保存用户名和密码。检查它们是否正确并为该特定用户加载仪表板。

如果他们被重定向到例如 www.your-domain.com/jpn.html,这是不安全的,因为 a) 它可以被搜索引擎索引并出现在搜索结果中,b) 更重要的是,所有用户都可以相互访问只需键入用户 URL 即可使用仪表板。

于 2010-12-15T10:24:19.243 回答