coppens Posted July 27, 2015 Share Posted July 27, 2015 Good day, I seem to be at a loss on the script that I am missing. I have four levels of users ranging from level 0, 1, 2, 3. Depending on the users user level, I would like them to be directed to one of 4 pages. In essence, a different home screen for each user level. I have attached my php script. Any help would be wonderful. Thank you! <?php require_once('Connections/Connect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?> <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['UserName'])) { $loginUsername=$_POST['UserName']; $password=$_POST['Password']; $MM_fldUserAuthorization = "UserLevel"; $MM_redirectLoginSuccess = "ConnectHome.php"; $MM_redirectLoginFailed = "Login.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_Connect, $Connect); $LoginRS__query=sprintf("SELECT UserName, Password, UserLevel FROM users WHERE UserName=%s AND Password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $Connect) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'UserLevel'); 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']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?> Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted July 27, 2015 Share Posted July 27, 2015 May I ask why you are creating different versions of script for different PHP versions? I suppose this makes sense if you are creating a framework for others to use, but expect this is not the case. There also appears to be a bunch more superfluous script which doesn't appear to relate to providing a different home page for users of different access level. If it is a book or tutorial you are following, I would suggest you find another. Try to keep it simple. When the user logs on, store their ID in a session. When you page is accessed, get the user's access level from the DB, and use a switch statement or some other means to display the content desired. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.