Guest User

Untitled

a guest
Aug 12th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ?>
  4. <?php
  5. $host_db = "localhost";
  6. $user_db = "database1";
  7. $pass_db = "mypass";
  8. $db_name = "usuariodatabase";
  9. $conexion = new mysqli($host_db, $user_db,$pass_db, $db_name);
  10.  
  11. if ($conexion->connect_error)
  12. {
  13. die("Conexion fallida con la base de datos" . $conexion->connect_error);
  14. }
  15. $username = $_POST['username'];
  16. $password = $_POST['password'];
  17.  
  18. $sql = "SELECT * FROM `usuarios` WHERE `usuario`='$username';";
  19. $result = $conexion->query($sql);
  20.  
  21. if ($result->num_rows > 0){
  22. }
  23. $row = $result->fetch_array(MYSQLI_ASSOC);
  24.  
  25. if (password_verify($password, $row['contrasena']))
  26. {
  27. //AQUI GUARDO LAS VARIABLES DE LA BD PARA SER USADAS EN PANEL-CONTROL.PHP
  28. $_SESSION['loggedin'] = true;
  29. $_SESSION['usuario'] = $username;
  30. $_SESSION['start'] = time();
  31. $_SESSION['expire'] = $_SESSION['start'] + (5 * 800000);
  32.  
  33. echo "Bienvenido! ".$_SESSION['usuario'];
  34. echo "<br><br><a href=panel-control.php>PANEL DE CONTROL</a>";
  35.  
  36. }
  37. else
  38. {
  39. echo "Usuario o contraseña estan incorrectos.";
  40. echo "<br><a href='logearse.html'>Volver a Intentarlo</a>";
  41.  
  42. }
  43. mysqli_close($conexion);
  44. ?>
  45.  
  46. <?php
  47. session_start();
  48. $now = time();
  49.  
  50. if($now > $_SESSION['expire'])
  51. {
  52. session_destroy();
  53. echo "Su sesion a terminado,
  54. <a href='index.html'>Necesita Hacer Login</a>";
  55. exit;
  56. }
  57. ?>
  58. <HTML>
  59. <body>
  60. <input id=input1>
  61. <input id=input2>
  62. </body>
  63. </HTML>
Add Comment
Please, Sign In to add comment