Mira lo que yo hago es lo siguiente hace mucho tiempo que tengo este codigo no se de quien sera, ni quien lo hizo lo unico hice algunos cambios y lo uso para mis proyectos
<?php require_once('../Control/conexiones/Coneccion_Apl.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
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;
}
}
$query_Apl_Login_Usuario = "SELECT * FROM usuarios ORDER BY nivel ASC";
?>
<?php
// *** Validate request to login to this site.
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['usuario'])) { $loginUsername=$_POST['usuario'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "nivel";
$MM_redirectLoginSuccess = "../Control/Administrador/inicio.php";
$MM_redirectLoginSuccess2 = "../Control/Socio/inicio.php";
$MM_redirectLoginSuccess3 = "../Control/Supervisor/inicio.php";
$MM_redirectLoginFailed = "index.php";
$MM_redirecttoReferrer = false;
$LoginRS__query=sprintf("SELECT usuario, clave, nivel FROM usuarios WHERE usuario=%s AND clave=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
if ($loginFoundUser) {
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
if($loginStrGroup==1) { header("Location: " . $MM_redirectLoginSuccess ); } if($loginStrGroup==2) { header("Location: " . $MM_redirectLoginSuccess2 ); } if($loginStrGroup==3) { header("Location: " . $MM_redirectLoginSuccess3 ); } }
else {
header("Location: ". $MM_redirectLoginFailed ); }
}
?>
En esta linea de codigo se le da el nivel que puede acceder
En este caso el nivel es 0 como todo usuario puede se admite el ingreso.
En el caso de un admin o lo que se de se cambia el nivel
<?php
?>
Al final de la pagina.
Pagina del Administrador.
<?php
//initialize the session
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); }
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']); unset($_SESSION['MM_UserGroup']); unset($_SESSION['PrevUrl']);
$logoutGoTo = "../index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo"); }
}
?>
<?php
}
$MM_authorizedUsers = "1";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); $isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "../index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized
("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; $MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); }
?>
En este punto de codigo se define, cual es el nivel de acceso
$MM_authorizedUsers = "1";
$MM_donotCheckaccess = "false";
Espero que te ayude