-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingresar.php
104 lines (92 loc) · 3.39 KB
/
ingresar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
require "php/error_handler.php";
require "class/class.database.php";
session_start();
//If para revisar si sesion de usuario existe
if(isset($_SESSION['usuario'])){
//Redirecciona a pagina de panel de control
header("Location: cpanel.php");
exit();
}
$database = new database();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Parroquia Santa Catarina</title>
<link rel="icon" href="img/logo_vertical_black.png">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-grid.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-grid.min.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-reboot.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-reboot.min.css">
<link rel="stylesheet" type="text/css" href="css/style_ingresar.css">
<style>
.error_msg{
color: red;
text-align: left;
}
</style>
<script>
function validarFormulario(){
var usuario = document.getElementById("usuario").value;
var contrasena = document.getElementById("contrasena").value;
var error_msg = document.getElementById("error");
if(usuario === "" || contrasena === ""){
error_msg.innerHTML = "* Por favor ingresar un usuario y una contraseña.";
return false;
}
}
function mostrarErrorLogin(){
var error_msg = document.getElementById("error");
error_msg.innerHTML = "* El usuario o contraseña es incorrecta.";
}
</script>
</head>
<body class="text-center" id="body">
<form class="form-signin" action="" method="post" onsubmit="return validarFormulario()">
<img class="mb-4" src="img/logo_horizontal_black.png" width="100%">
<input type="text" id="usuario" name="usuario" class="form-control" placeholder="Usuario" autofocus>
<input type="password" id="contrasena" name="contrasena" class="form-control" placeholder="Contraseña">
<input class="btn btn-lg btn-primary btn-block" type="submit" name="frmLogin" value="Ingresar">
<a href="index.php">Regresar</a>
<p class="error_msg" id="error">
</p>
</form>
<?php
if(isset($_POST["frmLogin"]) && $_POST["frmLogin"] == "Ingresar"){
//Variables de usuario y contrasena
$usuario = $_POST["usuario"];
$contrasena = $_POST["contrasena"];
//Linea de SQL para querry
$sql = "select * from usuario where usuario='".$usuario."' and contrasena='".$contrasena."'";
//Funcion que retorna el resultado del query
$result = $database->executeQuery($sql);
//If para revisar si existen registros
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
//Crea sesion con usuario
$_SESSION['usuario'] = $row["id_usuario"];
header("Location: cpanel.php");
exit();
}
}
else{
?>
<script>mostrarErrorLogin();</script>
<?php
}
}
?>
<script src="bootstrap/bootstrap.bundle.js"></script>
<script src="bootstrap/bootstrap.bundle.min.js"></script>
<script src="bootstrap/bootstrap.js"></script>
<script src="bootstrap/bootstrap.min.js"></script>
</body>
</html>
<?php
$database->closeConnection();
?>