Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.56 KB | None | 0 0
  1. INDEX.PHP
  2.  
  3. <html>
  4. <head>
  5. <title>.: Sistema de Login - Área inicial</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <div id="principal">
  11.  
  12.     <?php include "conexao.php"; ?>
  13.  
  14.     <form action="logar.php" method="post">
  15.    
  16.         Usuario:<br />
  17.         <input type="text" name="usuario" /><br />
  18.         Senha:<br />
  19.         <input type="password" name="senha" /><br /><br />
  20.         <input type="submit" value="Logar" />
  21.  
  22.     </form>
  23.     <br />
  24.     Esqueceu sua senha?
  25.     <br />
  26.     <br />
  27.     Novo usuário? Clique <a href="cadastro.php">aqui</a> e cadastra-se!
  28.    
  29. </div>
  30.  
  31. </body>
  32.  
  33. </html>
  34.  
  35.  
  36.  
  37. *****************************************************************************
  38. LOGAR.PHP
  39.  
  40. <?php
  41.  
  42.    include "conexao.php";
  43.  
  44.    $usuario = $_POST['usuario'];
  45.    $senha   = $_POST['senha'];
  46.  
  47.    $log  = mysql_query("SELECT * FROM sistema_login WHERE usuario = '$usuario'");
  48.    $cont = mysql_num_rows($log);
  49.    while($linha = mysql_fetch_array($log)){
  50.  
  51.        $senha_db = $linha['senha'];
  52.  
  53.    }
  54.    if($cont == 0){
  55.  
  56.        echo "
  57.        <meta HTTP-EQUIV=REFRESH CONTENT='0; URL=index.php'>
  58.         <script type=\"text/javascript\">
  59.             alert(\"O nome de usuário não corresponde.\");
  60.         </script>
  61.         ";
  62.     }
  63.     elseif($senha_db != $senha){
  64.        
  65.         echo "
  66.         <meta HTTP-EQUIV=REFRESH CONTENT='0; URL=index.php'>
  67.         <script type=\"text/javascript\">
  68.             alert(\"A senha não corresponde.\");
  69.         </script>
  70.         ";
  71.    
  72.     }
  73.     else{
  74.    
  75.         session_start();
  76.         $_SESSION['login_usuario'] = $usuario;
  77.         $_SESSION['senha_usuario'] = $senha;
  78.        
  79.         header('Location: login.php');
  80.    
  81.     }
  82.    
  83.     mysql_close($sql);
  84.  
  85.  ?>
  86.  
  87.  
  88.  
  89. *****************************************************************************
  90. CADASTRO.PHP
  91.  
  92. <html>
  93. <head>
  94. <title>.: Cadastrar novo usuario</title>
  95. </head>
  96.  
  97. <body>
  98.  
  99. <div id="principal">
  100.  
  101.     <?php include "conexao.php"; ?>
  102.    
  103.     <form action="enviar_dados.php" method="post" >
  104.    
  105.         Nome Completo:<br />
  106.         <input type="text" name="nome" /><br />
  107.         Email:<br />
  108.         <input type="text" name="email" /><br />
  109.         Nome de Usuário:<br />
  110.         <input type="text" name="usuario" /><br />
  111.         Senha:<br />
  112.         <input type="password" name="senha" /><br />
  113.         <br />
  114.         <input type="submit" value="Cadastrar" />
  115.  
  116.     </form>
  117.  
  118. </div>
  119.  
  120. </body>
  121.  
  122. </html>
  123.  
  124.  
  125.  
  126.  
  127. *****************************************************************************
  128. ENVIAR_DADOS.PHP
  129.  
  130. <?php
  131.  
  132.    include "conexao.php";
  133.  
  134.    $nome    = $_POST['nome'];
  135.    $email   = $_POST['email'];
  136.    $usuario = $_POST['usuario'];
  137.    $senha   = $_POST['senha'];
  138.  
  139.    $enviar_dados = mysql_query("INSERT INTO sistema_login (nome, email, usuario, senha) values ('$nome', '$email', '$usuario', '$senha')" );
  140.  
  141.    header('Location: index.php');
  142.  
  143. ?>
  144.  
  145.  
  146.  
  147.  
  148. *****************************************************************************
  149. LOGIN.PHP
  150.  
  151. <html>
  152. <head>
  153. <title>.: Área restrita</title>
  154. </head>
  155.  
  156. <body>
  157.  
  158. <h1>VOCÊ ESTÁ <font color="green">LOGADO</font>!</h1>
  159.  
  160. Clique <a href="index.php">aqui</a> para deslogar
  161.  
  162. </body>
  163.  
  164. </html>
  165.  
  166.  
  167.  
  168.  
  169. *****************************************************************************
  170. CONEXAO.PHP
  171.  
  172. <?php
  173.  
  174.     $sql = mysql_connect("localhost", "root", "")  or die ("Falha ao tentar conectar com banco de dados" .mysql_error());
  175.     $bd  = mysql_select_db("teste_projetos", $sql) or die ("Falha ao tentar conectar com banco de dados" .mysql_error());
  176.    
  177. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement