Morning All,
I am new to PHP and need alter the below auth page to allow for multiple user roles.
Different roles:
‘user role : admin’ log in and be redirected to admin page
‘user role : contributor’ log in and be redirected to contributor page
‘user role : viewer’ log in and be redirected to viewer page
Could any1 assist here?
My current code:
<?
session_start();
$_SESSION[‘authuser’] = 0;
include(‘db_auth.php’);
//Check username and password information
$sql = “SELECT * FROM auth”;
$result = mysql_query($sql)
or die(“Invalid query: ” . mysql_error());
while ($row = mysql_fetch_array($result)) {
$user = $row[‘user’];
$pass = $row[‘pass’];
$role = $row[‘role’];
if (((strtolower($_POST[‘user’])) == $user) and ((strtolower($_POST[‘pass’])) == $pass))
{
$_SESSION[‘authuser’] = 1;
if ($role == “administrator”) { $_SESSION[‘authuser’] = 2; }
}
//echo $user . “<br />”;
//echo $pass . “<br />”;
//echo $level . “<br />”;
//echo $_SESSION[‘authuser’] . “<br /><br />”;
}
//print_r($_POST);
//echo “<br /><br />”;
//print_r($_SESSION);
//echo “<br /><br />”;
//send user to ADMIN.php if auth or back to INDEX.php
if ($_SESSION[‘authuser’] == 2) {
$_SESSION[‘username’] = $_POST[‘user’];
header(“location:../db/administrator/admin.php”);
//echo “Auth user: ” . $_SESSION[‘authuser’];
} else {
$_SESSION[‘login_error’] = “error”;
header(“location:../administrator.php”);
//echo $_SESSION[‘login_error’];
}
?>