Help with page redirects

Forum
Last Post
Threads / Messages

GeneticAlpha

Loving Mysidia!
Member
Joined
May 24, 2020
Messages
289
Points
28
Age
31
Location
Tennessee
Mysidian Dollar
13,392
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.
 
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.
 
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;

}
 
Last edited:
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:
$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:
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!
 
Last edited:
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:
$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:
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!
Thanks so much! this is very helpful.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,129
Members
1,603
Latest member
Monako
BETA

Latest Threads

Latest Posts

Top