Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Galera, estou montando um sistema de login com nivel de acesso.
Ele possue a pagina de login.php, cadastro.php, painel.php , painel_admin.php, usuario.php,
Ok...
A Pessoa faz o login , dai vai pra pagina Painel.php, onde verifica se ele esta logado, e por fim vem esse código: if($_SESSION['usuario']['nivel'] == 0){
header("Location: usu.php");
}else{
header("Location: painel_admin.php");
}
Só que quando entra como usuario, ele vai pra pagina de usu, qnd entra como admin ele vai pra pagina de usu tb, Não sei oq é, o Valor de admin e 1 e de usu e 0.
Na pagina cadastro tb ta dando problema, eu crio a conexão normal, dai eu Deleto o campo ID e o campo Nivel. Mas dai quando se cadastra, ele fala que o campo Nivel no Mysql não é NULL, ou seja, quando se cadastrar, ele deveria colocar o nivel como 0, mas na propria MySql eu coloquei como valor padrão 0.
Preciso de ajuda...
Primeira coisa
>> Verifique o valor de antes e depois dando um echo na tela (ver se a variável não está em branco)
>> Está armazenando certinho na sessão?
se tudo isso já foi conferido (com 100% de certeza)..
>> Posta seu código
Dica: isso me cheira a variável não pegada... :lol:
mas qualquer coisa posta o código que ficarei feliz em ajudar
Ok, Vou postar o código do Cadastro.php e do Painel.php
Cadastro.php
<?php require_once('Connections/connection.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;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO users (id, nome, sobrenome, email, senha, nivel) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['nome'], "text"),
GetSQLValueString($_POST['sobrenome'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['senha'], "text"),
GetSQLValueString($_POST['nivel'], "int"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
$insertGoTo = "sucesso/cadastro.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_connection, $connection);
$query_Cadastro = "SELECT * FROM users";
$Cadastro = mysql_query($query_Cadastro, $connection) or die(mysql_error());
$row_Cadastro = mysql_fetch_assoc($Cadastro);
$totalRows_Cadastro = mysql_num_rows($Cadastro);
?>
<head>
<style type="text/css">
#form1 table tr td {
text-align: center;
}
a {
text-align: center;
color: #F00;
}
#form_login table tr td {
text-align: center;
}
select, input, textarea {
}
select, input, textarea {
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
font-style: normal;
color: #000;
text-decoration: none;
background-color: #8FEA3E;
border: thin solid #000;
}
.text {
text-align: center;
}
.text {
text-align: center;
}
.text {
text-align: center;
}
.text {
text-align: center;
}
.text {
text-align: center;
}
.text {
text-align: center;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cadastro de Usuários |</title>
</head>
<body>
</p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td colspan="2" align="right" nowrap class="text">Cadastro de Usuários</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Nome:</td>
<td><input type="text" name="nome" value="<?php echo $row_Cadastro['nome']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Sobrenome:</td>
<td><input type="text" name="sobrenome" value="<?php echo $row_Cadastro['sobrenome']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td><input type="text" name="email" value="<?php echo $row_Cadastro['email']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Senha:</td>
<td><input type="text" name="senha" value="<?php echo $row_Cadastro['senha']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Cadastrar"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html><?php
mysql_free_result($Cadastro);
?>
Painel.php
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "0,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.
if (!empty($UserName)) {
// 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);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "Erro/area.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 = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
if($_SESSION['email']['nivel'] == 1){
header("Location: painel_admin.php");header("Location: usu.php");
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Painel |</title>
</head>
<body>
</body>
</html>
no Painel.php, quando a value e 1 no MySQL, ele vai pro usu.php, qnd e 0 tb vai pro USU.php
No caso do cadastro, Fala q o campo nivel no MySQL não é NULL
Notice: Undefined index: id in C:\xampp\htdocs\cadastro.php on line 41
Notice: Undefined index: nivel in C:\xampp\htdocs\cadastro.php on line 46
Column 'nivel' cannot be null
Sendo q eu apagei o campo Nivel para não poder alterar o nivel.
tente assim