Last active
December 15, 2015 08:48
-
-
Save valdiney/5233201 to your computer and use it in GitHub Desktop.
Simples página de login o positivo é que funciona e o negativo é que não estou usando 'session' neste exemplo. Apenas verifica se os dados entrados são os mesmos que o da tabela "user". Se for satisfatório adentra em uma outra página, se não apresenta a mensagem de erro. Neste exemplo a validação dos campos que verifica se os mesmos estão em bra…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Projeto: Página com senha e usuario | |
Author:Valdinei França | |
Email:[email protected] | |
*/ | |
$link = mysql_connect("localhost",'root',''); | |
$banco = mysql_select_db("db_school"); | |
/*--CONEXAO COM O BANCO DE DADOS--*/ | |
$sql_mostrar = mysql_query("SELECT * FROM user"); | |
while($linha = mysql_fetch_array($sql_mostrar)){ | |
$pega_usuario = $linha['usuario']; | |
$pega_senha = $linha['senha']; | |
} | |
/*--CHAMANDO OS DADOS DA TABELA USER--*/ | |
$campo_usuario = $_POST['usuario']; | |
$campo_senha= $_POST['senha']; | |
if($_GET['funcao']=="fazer_login"){ | |
if($campo_usuario == $pega_usuario && $campo_senha == $pega_senha){ | |
header("Location:meu_admin.php"); | |
}else{ | |
$erro = "Usuario e senha incorretos"; | |
} | |
} | |
/*--VERIFICANDO SE SENHA E USUARIO SÃO OS MESMOS DA TABELA--*/ | |
?> | |
<!doctype html> | |
<html> | |
<head> | |
<script src="js/jquery-1.6.4.min.js"></script> | |
<link rel="stylesheet" href="css/style_index.css"/> | |
<title>BD SCHOOL</title> | |
<script> | |
$(document).ready(function(){ | |
$(".fieldset").hide(); | |
$("body").show('slow'); | |
$(".fieldset").slideDown('slow'); | |
var objeto_erro ={ | |
ocultar:function(){ | |
document.getElementById('erro').style.display = "none"; | |
}, | |
apresentar:function(){ | |
document.getElementById('erro').style.display = "block"; | |
} | |
}//end objeto erro | |
$("#submeter_login").click(function(){ | |
var usuario = document.getElementById('id_usuario').value; | |
var senha = document.getElementById('id_senha').value; | |
var erro = document.getElementById('erro'); | |
if(usuario =='' || senha ==''){ | |
objeto_erro.apresentar(); | |
erro.innerHTML = "Campos em branco! Digite usuario e senha."; | |
$('fieldset').addClass('fieldset'); | |
return false; | |
}else{ | |
$('fieldset').removeClass('fieldset'); | |
return true; | |
} | |
});//end click | |
});//end jquery | |
</script> | |
</head> | |
<body> | |
<header> | |
</header> | |
<fieldset class="fieldset"> | |
<div id="container_login"> | |
<form id="form_login" method="post" action="index.php?funcao=fazer_login"> | |
<table border="0"> | |
<tr> | |
<td><label for="id_usuario">Nome de Usuario:</label></td> | |
<td><input type="text" id="id_usuario" name="usuario"></td> | |
</tr> | |
<tr> | |
<td><label for="id_senha">Digite a senha:</label></td> | |
<td><input type="password" id="id_senha" name="senha"></td> | |
</tr> | |
<tr> | |
<td><button type="submit" id="submeter_login">Entrar</button></td> | |
</tr> | |
<tr> | |
<td><a id="links_alternativos" class="links_alternativos" href="#" title="Esqueci minha senha">Esqueceu sua senha?</a></td> | |
</tr> | |
<tr> | |
<p id="erro" class="erro"></a> | |
<p id="erro_viaphp"><?php echo $erro ?></p> | |
</tr> | |
</table> | |
</form> | |
</div><!--end container_login--> | |
</fieldset> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bem estruturada.