after login redirect to page according to user_level
Hi Jason
Here is my code for redirecting users to pages according to their level (userRole). I receive the following warning, when I browse:-
Notice: Undefined index: UserRole in C:\xampp\htdocs\Online_Site\Login.php on line 44
The "UserRole" is a column in users table in my mysql database.
The other code is created by dreamweaver. I just inserted your code with the modification according to my database
What can I do to make it work. I appreciate your assistance
mysql_select_db($database_MySQLonlineCoonetcion, $MySQLonlineCoonetcion);
$query_getCustomers = "SELECT * FROM users ORDER BY UserRole ASC";
$getCustomers = mysql_query($query_getCustomers, $MySQLonlineCoonetcion) or die(mysql_error());
$row_getCustomers = mysql_fetch_assoc($getCustomers);
$totalRows_getCustomers = mysql_num_rows($getCustomers);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
$user = $_SESSION['userRole']; //---- This is line 44
switch($user) {
case "admin":
header("Location: admin-index.php");
break;
case "client":
header("Location: clerk-index.php");
break;
case "clerk":
header("Location: client-index.php");
break;
case "guest":
header("Location: guest-index.php");
break;
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['loginbtn'])) {
// loginbtn is a hidden fieldtext has the value of 1 to ensure the login form has been submitted.
$loginUsername=$_POST['UserName'];
$password=$_POST['UserPW'];
$MM_fldUserAuthorization = $_GET['UserRole'];
$MM_redirectLoginSuccess = "/public_html/Admin/ClerkAdmin/clerk-index.php";
$MM_redirectLoginFailed = "/public_html/Login.html";
$MM_redirecttoReferrer = true;
mysql_select_db($database_MySQLonlineCoonetcion, $MySQLonlineCoonetcion);
$LoginRS__query=sprintf("SELECT UserName, UserPassword FROM users WHERE UserName=%s AND UserPassword=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $MySQLonlineCoonetcion) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
}
?>