Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Help with page redirects (http://www.mysidiaadoptables.com/forum/showthread.php?t=5727)

Micolai 04-08-2021 06:04 PM

Help with page redirects
 
Does anyone know how I go about making a page only viewable by visitors, so if you're already a member it just takes you to a specific page? I know how to do page redirects, but I need something that checks to see if you're a specific group.

Basically I'm wanting my members to not be able to go to the home page unless logged out. So only visitors can access the page.

Kyttias 04-10-2021 04:00 AM

You can use $mysidia->user->usergroup->gid to get the numerical value of the usergroup the current viewer has and block 'em out that way. Alternatively, $mysidia->user->usergroup should pull up a string version that is the name of the group. I can't remember off the top of my head what all the default usergroups are.

Micolai 04-10-2021 11:18 AM

Does all this need done in the login.php file or index.php file? I'm so confused lol. The visitor group I think is the guest group and it's all number 6.

Edit:

Oh my gosh!!! I got it! I had it in the wrong file! This is what I used:

$group = $mysidia->db->select("users", array("usergroup"), "gid ='{$mysidia->user->gid}'")->fetchColumn();
switch($group){

case 1; //admin

$document->add(new Comment("<meta http-equiv='refresh' content='0; URL=http://www.dinotracks.mysidiahost.com/account' />"));

case 2; //deluxe

$document->add(new Comment("<meta http-equiv='refresh' content='0; URL=http://www.dinotracks.mysidiahost.com/account' />"));

break;

case 3; //member

$document->add(new Comment("<meta http-equiv='refresh' content='0; URL=http://www.dinotracks.mysidiahost.com/account' />"));
break;

case 4; //beta tester

$document->add(new Comment("<meta http-equiv='refresh' content='0; URL=http://www.dinotracks.mysidiahost.com/account' />"));

break;

case 5; //moderator

$document->add(new Comment("<meta http-equiv='refresh' content='0; URL=http://www.dinotracks.mysidiahost.com/account' />"));

break;

case 6; //visitor



break;

}

Kyttias 04-11-2021 01:43 PM

So you know, you don't have to make a query for that information, its in the variable $mysidia->user->usergroup->gid, which exists in exactly the same way $mysidia->user->gid did in your query..

PHP Code:

$redirect "";
switch (
$mysidia->user->usergroup->gid){
  case 
1$redirect"yes"; break;
  case 
2$redirect"yes"; break;
  case 
3$redirect"yes"; break;
  case 
4$redirect "yes"; break;
  case 
5$redirect"yes"; break;
  default; 
$redirect "no";
}
if (
$redirect == "yes"){
  
$document->add(new Comment("<meta http-equiv='refresh' content='0; URL=http://www.dinotracks.mysidiahost.com/account' />"));


Which works great if you want to, in the future, redirect to different areas for the different groups, I guess...? But if you're only wanting different behavior for one of them... You could literally just do this in one if statement (if user group id does not equal 6, then redirect).

PHP Code:

if ($mysidia->user->usergroup->gid !== 6){
  
$document->add(new Comment("<meta http-equiv='refresh' content='0; URL=http://www.dinotracks.mysidiahost.com/account' />"));


I'm not sure if you could get away with a php header redirect with Mysidia's messiness, but I don't think have things up and running to test it out - so if your html redirect is good enough for your purposes, great!


All times are GMT -5. The time now is 02:35 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.