Advertisement
Guest User

Untitled

a guest
Feb 7th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?php
  2. session_start();
  3. global $tipo_usuario;
  4. if($_SESSION['tipo_usuario']){
  5. $tipo_usuario = $_SESSION['tipo_usuario'];
  6. }
  7.  
  8. ?>
  9. <!DOCTYPE html>
  10. <html lang="es">
  11. <head>
  12. <meta charset="UTF-8">
  13. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  14. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  15. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
  16. <link rel="stylesheet" href="css/login.css">
  17. </head>
  18. <?php
  19. if ($tipo_usuario == "Admin") {
  20. require("navbarIniciadoAdmin.html");
  21. //echo($tipo_usuario);
  22. } else if ($tipo_usuario == "User") {
  23. require("navbarIniciadoUser.html");
  24. //echo($tipo_usuario);
  25. } else {
  26. require("navbarNoIniciado.html");
  27. //echo($tipo_usuario);
  28. }
  29. ?>
  30. </html>
  31.  
  32. <?php
  33. if (isset($_POST['login-submit'])) {
  34. login();
  35. } else {
  36. header("Location: ../index.php");
  37. exit();
  38. }
  39.  
  40. function login() {
  41. require 'dbc-inc.php';
  42.  
  43. $nombreUsuario = $_POST['username'];
  44. $password = $_POST['password'];
  45.  
  46. if (empty($nombreUsuario) || empty($password)) {
  47. header("Location: ../index.php?error=emptyfields&username=" . $nombreUsuario);
  48. exit();
  49. } else {
  50. $sql = "SELECT * FROM usuarios WHERE NOMBRE_USUARIO = ?;";
  51. $stmt = mysqli_stmt_init($connection);
  52. if (!mysqli_stmt_prepare($stmt, $sql)) {
  53. header("Location: ../index.php?error=sqlerror");
  54. exit();
  55.  
  56. } else {
  57.  
  58. mysqli_stmt_bind_param($stmt, "s", $nombreUsuario);
  59. mysqli_stmt_execute($stmt);
  60. $result = mysqli_stmt_get_result($stmt);
  61.  
  62. if ($row = mysqli_fetch_assoc($result)) {
  63. $checkPassword = password_verify($password, $row['PWD_USUARIO']);
  64. if ($checkPassword == false) {
  65. header("Location: ../index.php?error=ContraseñaIncorrecta");
  66. exit();
  67. } else if ($checkPassword == true) {
  68. $contador = 1;
  69. session_start();
  70. $_SESSION['id_usuario'] = $row['ID_USUARIO'];
  71. $_SESSION['nombre_usuario'] = $row['NOMBRE_USUARIO'];
  72. $_SESSION['tipo_usuario'] = $row['TIPO_USUARIO'];
  73.  
  74.  
  75. header("Location: ../documentos.php?success=login");
  76. exit();
  77. } else {
  78. header("Location: ../index.php?error=ContraseñaIncorrecta");
  79. exit();
  80. }
  81. } else {
  82. header("Location: ../index.php?error=noUser");
  83. exit();
  84. }
  85. }
  86. }
  87. }
  88.  
  89. if($_SESSION['tipo_usuario']){
  90. $tipo_usuario = $_SESSION['tipo_usuario'];
  91. }
  92.  
  93. if (isset($_SESSION['tipo_usuario']) && !empty($_SESSION['tipo_usuario']) {
  94. $tipo_usuario = $_SESSION['tipo_usuario'];
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement