Jump to content
Larry Ullman's Book Forums

Redirecting A None Admin User - Php?


Recommended Posts

I am trying to create a script that redirect the none admin users.

The code below:

 

session_start();
function redirct_none_admin($check ='user_id', $target='index.php'){
if(!isset($_SESSION[$check])) {
 $url =  BASE_URL . $target;
 header("Location: $url");
 exit();
 }
}

 

function call:

// Redirect non-administrators:
redirct_none_admin('user_admin');

 

I could not redirect the none-admin user.

Is there anything wrong with this code? How to fix it?

Thank you.

Link to comment
Share on other sites

session_start();
function redirect_none_admin($target='index.php'){
   if(isset($_SESSION['user_id'])) {
   $url = BASE_URL . $target;
   header("Location: $url");
   exit();
   }
}

 

Function call:

 

// Redirect non-administrators:
redirect_none_admin();

Link to comment
Share on other sites

function redirct_none_admin($check ='user_id', $page='index.php'){

if(!isset($_SESSION[$check])) {

$url = BASE_URL . $page;

header("Location: $url");

exit();

} elseif($_SESSION['user_type'] != 'admin') {

$url = BASE_URL . $page;

header("Location: $url");

exit();

}

}

========================================

It is working but I do not know if it is the right way to do it.

Link to comment
Share on other sites

 Share

×
×
  • Create New...