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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...