<html>
<head>
<title>Cadastro usuários </title>
</head>
<body>
<form action="cadastro.php?acao=usuario" method="post" name="form1" target="_self">
<table width="762" border="0">
<tr>
<th width="480" scope="col"><div align="left"></div>
<table width="333" height="205" border="0" align="left">
<tr>
<th scope="col">Usuario:</th>
<th scope="col"> <div align="left">
<input name="usuario" type="text" id="usuario" />
</div></th>
</tr>
<tr>
<th scope="row">Senha:</th>
<td><div align="left">
<input name="senha" type="password" id="senha" />
</div></td>
</tr>
<tr>
<th scope="row">Nivel:</th>
<td><div align="left">
<select name="nivel" id="nivel">
<option value="1">Administrador</option>
<option value="2">Usuário Padrão</option>
<option value="3">Restrito</option>
<option value="0" selected="selected"></option>
</select>
</div></td>
</tr>
<tr>
<th colspan="2" scope="row"><div align="center">
<input type="submit" name="Submit" value=">>>Cadastrar<<<" />
</div>
<div align="left"></div></th>
</tr>
</body>
</html><?
include "config.php";
if($acao==usuario){
$usuario = $_POST["usuario"];
$senha = $_POST["senha"];
$nivel = $_POST["nivel"];
$sql = mysql_query("INSERT INTO tabela (usuario, senha, nivel) VALUES (UPPER('$usuario'), md5('$senha'), '$nivel')", $conexao) or die("Erro: " . mysql_error()); // faço a inserção no banco de dados.
if(($sql) > 0){
echo "Cadastro do usuário completo.";
}
else{
echo "erro ao tentar cadastrar o usuário.";
}
}
?><html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; ISO-8859-1" />
<style type="text/css">
td img {display: block;}body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style1 {
font-size: 12px;
color: #000000;
font-weight: bold;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
</style>
</head>
<body bgcolor="#ffffff">
<form id="form1" name="form1" method="post" action="login.php?acao=logar">
<table width="241" border="0" align="center">
<tr>
<th scope="col">Usuario:</th>
<th scope="col"><label>
<div align="left">
<input name="usuario" type="text" class="style1" id="usuario" size="10" />
</div>
</label></th>
</tr>
<tr>
<th scope="row">Senha:</th>
<td><label>
<div align="left">
<input name="senha" type="password" class="style1" id="senha" size="10" />
</div>
</label></td>
</tr>
<tr>
<th scope="row"> </th>
<td><label>
<div align="right">
<input type="submit" name="Submit" value="Logar" />
</div>
</label></td>
</tr>
</table>
</form>
<html><?
ob_start(); // utilizando este comando não terá problemas caso a pagina contenha conteudo html,
if($acao==logar){
include "config.php";
$usuario = $_POST["usuario"];
$senha = $_POST["senha"];
$sql = mysql_query("select * from tabela where usuario='$usuario' AND senha=MD5('$senha')"); /* verifico se o usuário e a senha estão corretos */
$sql2 = mysql_query("select `usuario`, `senha`, `nivel` from tabela where usuario='$usuario' LIMIT 0,1", $conexao); /* verifico o nivel do usuário logado */
$busca = mysql_num_rows($sql); /*verifico se ocorreu resultado*/
$array = mysql_fetch_array($sql2);/*se ocorreu crio um array para os dados recebidos */
$usuario = $array["usuario"];
$senha = $array["senha"];
$nivel = $array["nivel"];
if(($busca > 0) && ($array > 0)){ /* crio os cookies */
setcookie("usuario", $usuario);
setcookie("senha", $senha);
setcookie("nivel", $nivel);
header("location: admin.php");
}
else{
echo"Erro ao se logar.";
}
}
?><?
// Sistema para verificar se o usuário já está logado ou não
if(!$HTTP_COOKIE_VARS["usuario"] && !$HTTP_COOKIE_VARS["senha"]){
header("Location: login.html");
}
else
{
include "config.php";
$sql = mysql_query("select `nome`, `link`, `target`, `nivel` from tabela"); /* faço uma consulta na base selecionando o menu destinado ao nivel do usuário.*/
$usuario = $HTTP_COOKIE_VARS["usuario"]; /* crio uma variavel com o nome dousuário para ser apresentado apos o login ou para ser comparado caso queira mostrar o nome do usuário. */
$sql_1 = mysql_query("select `usuario`, `nome` from tabela where usuario='$usuario'"); /* consulto a tabelça de usuário para buscar o nome comparando o nome de usuário gravado no cookie recebendo informações somente do nome quer for igual ao usuário. */
$consulta = mysql_fetch_array($sql_1);
$nome = $consulta["nome"];
if($HTTP_COOKIE_VARS["nivel"] ==1){
echo "Seja Bem Vindo(a) <b>$nome</b>.";
echo " ";
echo "<a href='logoff.php?acao=sair' target='_top'>Logoff</a>";
echo "<hr>";
while($busca = mysql_fetch_array($sql)){ /* faço a verificação guardando as informações dos links que serão apresentados. */
$nome = $busca["nome"];
$link = $busca["link"];
$target = $busca["target"];
$nivel = $busca["nivel"];
if($nivel==1){ /* verifico se o nivel do menu apresentado é igual a 1 */
echo "<a href='$link' target='$target'><b>$nome</b></a>";
echo " ";
echo "<b>||</b>";
echo " ";
}//fecha if
}
}
if($HTTP_COOKIE_VARS["nivel"] ==2){
echo "Seja Bem Vindo(a) <b>$nome</b>.";
echo " ";
echo "<a href='logoff.php?acao=sair' target='_top'>Logoff</a>";
echo "<hr>";
while($busca = mysql_fetch_array($sql)){
$nome = $busca["nome"];
$link = $busca["link"];
$target = $busca["target"];
$nivel = $busca["nivel"];
if($nivel==2){
echo "<a href='$link' target='$target'><b>$nome</b></a>";
echo " ";
echo "<b>||</b>";
echo " ";
}//fecha if
}
}
}
?>
![]() |
CodigoFonte.net » CodigoFonte.eti.br » Compre De Tudo » Meu Mural » Competiva - Criação de Sites » Todos os Direitos Reservados © 2002/2010 |
Procurando Notebooks, Câmeras Digitais, iPhones?