MyBB Community Forums

Full Version: Is this code written correctly? {{ re-direct based on user-group }} Any suggestions??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
To re-direct after login based on user-group:
In member.php search for

redirect("index.php", $lang->redirect_registered);

change to: (for example)

if($mybb->user['usergroup'] == 1) {
	redirect("forum1.php", $lang->redirect_registered1);
} 

elseif($mybb->user['usergroup'] == 2) {

	redirect("example2.php", $lang->redirect_registered2);
}

elseif($mybb->user['usergroup'] == 3) {

	redirect("forum3.php", $lang->redirect_registered3);
}

elseif($mybb->user['usergroup'] == 4) {

	redirect("example4.php", $lang->redirect_registered4);
}

else {
redirect("forum5.php", $lang->redirect_registered5);
}

Quick, easy questions

1) Do I need the { brackets? }
...or for this type of simple code, or should it be...

elseif($mybb->user['usergroup'] == 3)
redirect("forum3.php", $lang->redirect_registered3);

2) How about the space? I've seen examples both ways, so both must work? Huh
if(
or
if (

##

Any suggestions on writing this better, or is it good enough now?
Thank you very much.
^^ Give both a shot! Make a short test script and try it out (I could answer it now, but I won't spoil the surprise).

For a suggestion, you might want to try using a switch statement instead of all those elseif combination, but there really isn't that much of a difference.





































































Braces are optional if there's only a single line of code following the if/else/for/while statement, but having braces is harmless. Yes, you can have a space between the if and the bracket, or you can chose to omit it.
Thanks for the advice...


































































You are a great addition to the MyBB community. I could have mentioned this sooner, but why spoil the surprise.
Also, if you have a string in PHP which doesn't have any variables in it, you can use a single quote around the string instead of a double quote. If memory serves, this is faster.