Last active
May 31, 2025 22:14
-
-
Save gabcarvalhogama/f5f94c2cef8b9cba9a90 to your computer and use it in GitHub Desktop.
Como criar um sistema de Login em PHP(Sem MySQL)
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
| <!DOCTYPE html> | |
| <html lang="pt-br"> | |
| <head> | |
| <title>Sistema de Login :: Toolmmer</title> | |
| <meta charset="UTF-8" /> | |
| <!-- Estilos da Index.php --> | |
| <style type="text/css"> | |
| body{ | |
| background: linear-gradient(45deg, #f0f9ff 10%, #cbebff 47%, #a1dbff 100%); | |
| } | |
| div.global{ | |
| width: 40%; | |
| height: auto; | |
| background-color: #fff; | |
| border: 1px solid #606060; | |
| padding: 50px; | |
| box-shadow: 0px 0px 10px #000; | |
| margin-top: 10%; | |
| /* Centralizando a div | |
| *O atributo text-align foi depreciado. | |
| */ | |
| margin-left: auto; | |
| margin-right: auto; | |
| } | |
| input[type='text'], input[type='password']{ | |
| width: 300px; | |
| height: 25px; | |
| border: solid 1px #606060; | |
| border-radius: 5px; | |
| } | |
| input[type='password']{ | |
| margin-left: 10px; | |
| } | |
| input[type='submit']{ | |
| width: 150px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="global"> | |
| <!-- Aqui temos o formulário | |
| *Action é vazia por que vamos fazer a validação e o redirecionamento nesta mesma página. | |
| --> | |
| <form name="" method="post" action=""> | |
| <label>Usuário: <input type="text" name="user" /></label><br /><br /> | |
| <label>Senha: <input type="password" name="pass" /></label><br /><br /> | |
| <input type="submit" name="submit" value="Logar!" /> | |
| </form> | |
| <?php | |
| /* Declaração de Variáveis */ | |
| $user = @$_REQUEST['user']; | |
| $pass = @$_REQUEST['pass']; | |
| $submit = @$_REQUEST['submit']; | |
| /* Declaração das variáveis que possuem os usuarios e as senhas */ | |
| $user1 = 'toolmmer'; | |
| $pass1 = 'a1b24d'; | |
| $user2 = 'gabrielsooco'; | |
| $pass2 = 'b3gabriel'; | |
| /* Testa se o botão submit foi ativado */ | |
| if($submit){ | |
| /* Se o campo usuário ou senha estiverem vazios geramos um alerta */ | |
| if($user == "" || $pass == ""){ | |
| echo "<script:alert('Por favor, preencha todos os campos!');</script>"; | |
| } | |
| /* Caso o campo usuario e senha não | |
| *estejam vazios vamos testar se o usuário e a senha batem | |
| *iniciamos uma sessão e redirecionamos o usuário para o painel */ | |
| else{ | |
| if(($user == $user1 && $pass == $pass1) || ($user == $user2 && $pass == $pass2)){ | |
| session_start(); | |
| $_SESSION['usuario']=$user; | |
| $_SESSION['senha']=$pass; | |
| header("Location: painel.php"); | |
| } | |
| /* Se o usuario ou a senha não batem alertamos o usuario */ | |
| else{ | |
| echo "<script>alert('Usuário e/ou senha inválido(s), Tente novamente!');</script>"; | |
| } | |
| } | |
| } | |
| ?> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fala ami
Fala amigo, pena não ter ajudado, se surgir alguma dúvida que não encontrar sobre trabalhar com as arrays, pode mandar que, se eu souber, ficarei feliz em ajudar. Abraço