Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. <?php
  2.  
  3. ?>
  4.  
  5.  
  6. <!DOCTYPE html>
  7. <html lang="es">
  8. <head>
  9. <meta charset="utf-8">
  10. <title>Login</title>
  11.  
  12. </head>
  13. <body>
  14. <div>
  15. <center>
  16. <form method="POST" action="validar.php">
  17. <input type="text" name="nombre" placeholder="Usuario">
  18. <br>
  19. <input type="password" name="password" placeholder="Contraseña"><br>
  20. <button type="submit">Iniciar Sesion</button>
  21.  
  22. </form>
  23. </center>
  24. </div>
  25. </body>
  26. </html>
  27.  
  28. <?php
  29. include 'conex.php';
  30. $usuario = $_POST['nombre'];
  31. $pass = $_POST['password'];
  32.  
  33. if(empty($usuario) || empty($pass)){
  34. header("Location: index.php");
  35. exit();
  36. }
  37. $query=("SELECT * FROM usuarios where Username='".$usuario."'");
  38. echo var_dump($query);
  39. $res = $con->query($query);
  40. if($row = mysql_fetch_array($res)){
  41. if($row['Password'] == $pass){
  42. session_start();
  43. $_SESSION['usuario'] = $usuario;
  44. header("Location: inicio.php");
  45. }
  46. else
  47. {
  48. header("Location: index.php");
  49. exit();
  50. }
  51. }
  52. else
  53. {
  54. header("Location: index.php");
  55. exit();
  56. }
  57. ?>
  58.  
  59. if (empty($usuario) || empty($pass)) {
  60. header("Location: index.php");
  61. exit();
  62. }
  63.  
  64. if (!isset($_SESSION)) {
  65. session_start();
  66. }
  67. if (isset($_SESSION['usuario'])) {
  68. header("Location: inicio.php");
  69. } else {
  70. // Sentencias...
  71. }
  72.  
  73. <label id="uno">Inicio de Sesión</label>
  74. <fieldset style="width:400px" id="cuadro">
  75. <form action="" method="post">
  76. <br>
  77. <label id="dos" for="username">Username: </label><input type="text" id="username" name="username" >
  78. <br><br>
  79. <label id="tres"for="pass">Password: </label><input type="password" id="pass" name="pass" >
  80. <br><br>
  81. <input type="submit" value="Iniciar Sesión" class="btn btn-primary">&nbsp&nbsp <input type="reset" value="Limpiar" class="btn btn-primary">
  82. </form>
  83. </fieldset>
  84. </center>
  85. <?php
  86. if(!empty($_POST['username'])){
  87.  
  88. include "Conex.php";
  89. include "User.php";
  90. $conex = new ConexionDB;
  91. $user = User::login(addslashes($_POST['username']),$_POST['pass'],$conex);
  92. //$userData=$user->getReturn();
  93. $userData=$user;
  94. if( !empty($userData) ){
  95. session_start();
  96. $_SESSION['user']=$userData;
  97. header('location:home.php');
  98. }else{
  99. echo "<br>";
  100. echo "<center><h3>Username o password incorrectos!</h3></center>";
  101. }
  102. }
  103. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement