If's loads, is everything alright?

I have a login form, and I designed my site in such a way that each user has his own panel.

After logging in, I check

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

etc. for 1500 usernames. This is normal?

+3
source share
6 answers

Put the names and URLs of the dashboard into the database. Make one search to find the URL based on the published name and redirect. You will have 4 lines of code instead of 6000.

+4
source

No. If you really need to choose between 1,500 different procedures, you should use something like a strategy template .

( ) . . ?

+1

, ... :)

script, script!

+1

-, , if , switch:

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

-, , -. . .

+1

1 .

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


dahsboard php 

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

1000 , .

0

, . , , , . , .

If they are redirected, for example, to www.your-domain.com/jpn.html, this is not safe, since a) it can be indexed by search engines and displayed in the search results, and b) more importantly, all users can access other users’s dashboards by simply typing the user’s URL.

0
source

Source: https://habr.com/ru/post/1780393/


All Articles