Jump to content

Recommended Posts

I need help with some code, basically I'm trying to write a code that will redirect a user to a page based on his group membership. I am fairly new to php so sorry if i don;t make sense.

 

This is what I have now, if the user belongs to Group 1 & 3 then dispay page or exit.

 

 if (!($check['team']=='Group 1') && !($check['team']=='Group 3'))
    {
        echo 'You are not allowed to access this page.';
	exit();
    }

 

I need to modify the code and make it so if logged in user belongs to Group 1 then redirect to group1.php, if group2 redirect to group2.php, if group3 then redirect to group3.php, or exit.

 

I was thinking of:

if (!($check['team']=='Group 1'));
  Header ("Location: http://www.mysite.com/group1.php");
elseif (!($check['team']=='Group 2'));
  Header ("Location: http://www.mysite.com/group2.php");
else
  echo "You are not allowed to access this page.";
exit();
    }

but it did not work.

Link to comment
https://forums.phpfreaks.com/topic/174282-solved-need-help/
Share on other sites

if ($check['team'] == 'Group 1') {

  // include or w.e

} elseif ($check['team'] == 'Group 2') {

  // whatever

} elseif ($check['team'] == 'Group 3') {

  // whatever 2

}

 

but you'd be better off with

 

switch ($check['team']) {

  case 'Group 1':

  break;

  case 'Group 2':

  break;

  case 'Group 3':

  break;

}

Link to comment
https://forums.phpfreaks.com/topic/174282-solved-need-help/#findComment-918721
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.