Pegar sessão de usuário
Amigos, não estou conseguindo pegar e guardar a sessão do usuário. Já tentei de várias formas e não obtive resultado. Segue abaixo os códigos completos das páginas index.php e da página para onde o usuário é direcionado após o login. index.php
<?php require_once('Connections/conexao.php').?>
<?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['usuario'])) { $loginUsername=$_POST['usuario']. $password=$_POST['senha']. $MM_fldUserAuthorization = "nivel_acesso". $MM_redirectLoginSuccess = "principal.php". $MM_redirectLoginFailed = "index.php?ac=erro". $MM_redirecttoReferrer = false. mysql_select_db($database_conexao, $conexao). $LoginRS__query=sprintf("SELECT usuario, senha, nivel_acesso FROM clientes WHERE usuario='%s' AND senha='%s'", get_magic_quotes_gpc()? $loginUsername: addslashes($loginUsername), get_magic_quotes_gpc()? $password: addslashes($password)). $LoginRS = mysql_query($LoginRS__query, $conexao) or die(mysql_error()). $loginFoundUser = mysql_num_rows($LoginRS). if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'nivel_acesso'). //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 ). }
}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="menu_assets/styles.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html. charset=iso-8859-1" />
<title>Login</title>
<script>
function valida(){ if (document.form1.usuario.value == "")
{
alert("Informe o seu nome de usuário."). document.form1.usuario.focus(). return false. } if (document.form1.senha.value == ""){
alert("Informe a sua senha."). document.form1.senha.focus(). return false. }
}
</script>
<style type="text/css"><!--
.style1 { color: #FFFFFF. font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif. font-size: 11px. }.style2 { font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif. font-size: 11px. font-weight:normal!important. } --></style>
</head> <body>
<div id="topo"></div>
<div align="center"><br /> <table width="1000" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table style="margin:0 auto. " width="30%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" height="134"> <? if(isset($_GET['ac'])){ if($_GET['ac'] == "erro"){ //escreve o erro?> <br /> <table width="84%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="35"><div align="center" style="font-family:verdana. padding-left: 56px. font-size:11px. color:#F00. ">Usuário/Senha Inválidos! </div></td> </tr> </table> <? } }?> <form id="form1" name="form1" method="POST" onsubmit="return valida(this)" action="<?php echo $loginFormAction.?>"> <table width="76%" border="0" align="center" cellpadding="0" cellspacing="5"> <tr> <td colspan="2" ></td> </tr> <tr> <td width="23%" ><div align="left"><span class="style21">Login:</span></div></td> <td width="77%" ><label> <div align="left"> <input class="formlogin" name="usuario" type="text" id="usuario" size="30" /> </div> </label></td> </tr> <tr> <td width="23%" ><div align="left"><span class="style21">Senha:</span></div></td> <td width="77%" ><label> <div align="left"> <input class="formlogin" name="senha" type="password" id="senha" size="30" /> </div> </label></td> </tr> <tr> <td colspan="2" > <label> <input style="font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif. font-size:11px. margin-left: 173px. " type="submit" name="Submit" value="ENTRAR" /> </label> </td> </tr> </table> </form> </td> </tr> </table> <div style="margin: 0 auto. padding-left: 158px. width: 200px. font-family:Verdana, Geneva, sans-serif. font-size:10px. " align="center" class="style2"><b><a style="font-weight:normal. color:#ffa200. " href="recuperarsenha.php">Esqueceu a senha?</a></b></div> <p> </p> <p> </p></td> </tr> <tr> <td><div align="center"><br /> <? include"rodape.php".?> <br /> </div></td> </tr> </table>
</div>
</body>
</html> principal.php <?php
session_start(). if( (!isset($_SESSION["usuario"])) || (!isset($_SESSION["senha"])) || (!isset($_SESSION["nivel_acesso"])) || (!isset($_SESSION["empresas_idempresas"]))) $MM_authorizedUsers = "admin1". $MM_donotCheckaccess = "false".?>
<?php require_once('../Connections/conexao.php').?><?php require_once('../Connections/conexao.php'). require_once('../include.php').?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html. charset=iso-8859-1" />
<link href="../css/style.css" rel="stylesheet" type="text/css">
<? include "menu.php".?>
<?php require_once("menu.php").?>
<?php // *** Restrict Access To Page: Grant or deny access to this pagefunction 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 = "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 = "&". if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) $MM_referrer.= "?". $QUERY_STRING. $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar. "accesscheck=". urlencode($MM_referrer). header("Location: ". $MM_restrictGoTo). exit. }?>
<?php
$colname_dados = "-1". if (isset($_SESSION['MM_Username'])) { $colname_dados = (get_magic_quotes_gpc())? $_SESSION['MM_Username']: addslashes($_SESSION['MM_Username']). }
mysql_select_db($database_conexao, $conexao). $query_dados = sprintf("SELECT * FROM usuarios WHERE usuario = '%s'", $colname_dados). $dados = mysql_query($query_dados, $conexao) or die(mysql_error()). $row_dados = mysql_fetch_assoc($dados). $totalRows_dados = mysql_num_rows($dados). $maxRows_faturas = 5. $pageNum_faturas = 0. if (isset($_GET['pageNum_faturas'])) { $pageNum_faturas = $_GET['pageNum_faturas']. }
$startRow_faturas = $pageNum_faturas * $maxRows_faturas. mysql_select_db($database_conexao, $conexao). $query_faturas = "SELECT * FROM boletos ORDER BY Id DESC". $query_limit_faturas = sprintf("%s LIMIT %d, %d", $query_faturas, $startRow_faturas, $maxRows_faturas). $faturas = mysql_query($query_limit_faturas, $conexao) or die(mysql_error()). $row_faturas = mysql_fetch_assoc($faturas). if (isset($_GET['totalRows_faturas'])) { $totalRows_faturas = $_GET['totalRows_faturas']. } else {
$all_faturas = mysql_query($query_faturas). $totalRows_faturas = mysql_num_rows($all_faturas). }
$totalPages_faturas = ceil($totalRows_faturas/$maxRows_faturas)-1.?>
<style type="text/css"><!--
.style1 { color: #FFFFFF. font-family: Verdana, Arial, Helvetica, sans-serif. font-size: 11px. }.style23 { font-family: Verdana, Arial, Helvetica, sans-serif. font-size: 16px. }.style10 { font-family: Verdana, Arial, Helvetica, sans-serif. font-size: 12px. }#form1 input {
font-size: 10px. background-color: #FFFFFF. border-top-style: ridge. border-right-style: ridge. border-bottom-style: ridge. border-left-style: ridge. }.style4 {font-size: 9px}.style5 {font-family: Verdana, Arial, Helvetica, sans-serif. font-size: 11px. color: #7BBE11. }.style6 {color: #000000}.style7 {color: #FF0000}-->
</style>
</head> <body>
<div align="center"><br /> <table width="1000" border="0" cellspacing="0" cellpadding="0"> <tr> <td ><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="134" valign="top"><br /> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td height="20" ><div class="style21" style="margin: 0 auto. text-align: center. width: 360px. ">Olá <strong><?php echo $row_dados['nome'].?></strong>, seja bem-vindo(a)!<br />Utilize o menu acima para acessar as funcionalidades do sistema.<br />Bom trabalho!</div></td> </tr> <tr> <td valign="top" ><div style="margin-left: 5px. " align="left"> <p><strong><br /> <span class="style2"> </span></strong><span class="style2"><br /> <br /> <? if($row_dados['nivel'] == "1"){ if($row_dados['nivel'] == "1"){ $sql_ac = "SELECT * FROM acoes". $exe_ac = mysql_query($sql_ac, $conexao). $num_ac = mysql_num_rows($exe_ac). if($num_ac > 0){ echo "<b>Atualizações</b>". echo "<br>Existem <strong><a href='atualizacoes.php'>$num_ac</a></strong> exclusões de faturas.". }else{ } }else{ }?> <br /> <? $sql_tip = "SELECT * FROM boletos WHERE situacao = '1'". $exe_tip = mysql_query($sql_tip, $conexao). $num_tip = mysql_num_rows($exe_tip). if($num_tip > 0){ echo "<strong>Faturas Em Aberto</strong><br>". echo "Você tem <strong><a href='pendentes.php'>$num_tip</a></strong> faturas(s) em aberto". echo "<br>". } $sql_tipo = "SELECT * FROM boletos WHERE situacao = '3'". $exe_tipo = mysql_query($sql_tipo, $conexao). $num_tipo = mysql_num_rows($exe_tipo). if($num_tipo > 0){ echo "<strong>Faturas Vencidas</strong><br>". echo "Você tem <strong><a href='vencidas.php'>$num_tipo</a></strong> fatura(s) vencidas". echo "<br>". } $sql_mss = "SELECT * FROM mensagens ORDER BY Id DESC". $exe_mss = mysql_query($sql_mss, $conexao). $num_mss = mysql_num_rows($exe_mss). if($num_mss > 0){ echo "<strong>MENSAGENS</strong><br>". echo "Há <strong><a href='listarmensagens.php' style='color:#F00. text-decoration:underline. '>$num_mss</a></strong> na caixa de mensagens". echo "<br>". }?> </span></strong><br /><? }?> <br /> <br /> </p> </div></td> </tr> <tr> <td height="21"></td> </tr> <tr> <td height="21" ><div align="center" class="style2"> </div></td> </tr> <tr> <td height="21" ><div align="left" class="titlepage">Últimas Faturas</div></td> </tr> <tr> <td > <? if($row_dados){?> <table class="bordasimples" width="99%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td class="titlegrid" width="8%"><div align="center" class="style3"><strong>Cód</strong></div></td> <td class="titlegrid" width="54%"><div align="center"><strong><span class="style3">Referência</span></strong></div></td> <td class="titlegrid" width="12%"><div align="center" class="style3"><strong>Valor</strong></div></td> <td class="titlegrid" width="12%"><div align="center" class="style3"><strong>Situação</strong></div></td> </tr> <?php do {?> <tr> <td height="22" ><div align="center" class="style21"><?php echo $row_faturas['Id'].?></div></td> <td ><div align="left"><span class="style21"><?php echo $row_faturas['referencia'].?></span></div></td> <td ><div align="center" class="style21">R$ <?php echo $row_faturas['valor'].?> </div></td> <td ><div align="center" class="style21"> <?php if($row_faturas['situacao'] == "1"){?> <span class="style6">PENDENTE</span> <? }else if($row_faturas['situacao'] == "2"){?> <span style="color:#090">PAGO</span> <? }else if($row_faturas['situacao'] == "3"){?> <span class="style7" style="color:#F00. ">VENCIDO</span> <? }?> </div></td> </tr> <?php } while ($row_faturas = mysql_fetch_assoc($faturas)).?> </table> <? }else{
echo "<p align = 'center' class='style2'>Você não tem permissão para acessar esta área!</p>". }?> <br /> <p align="center"> </p></td> </tr> </table> <p class="style2"> </p></td> </tr> </table> <p> </p></td> </tr> <tr> <td><div align="center"><br /> <? include"../rodape.php".?> <br /> </div></td> </tr> </table>
</div>
</body>
</html>
<?php
mysql_free_result($dados). mysql_free_result($faturas).?> Alguém pode me ajudar a resolver esse problema?:D Abraços a todos!Discussão (6)
Carregando comentários...