-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
52 lines (42 loc) · 1.41 KB
/
login.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
<?php
session_start();
if (isset($_SESSION['user_id'])) {
header('Location: /php-login');
}
require 'database.php';
if (!empty($_POST['email']) && !empty($_POST['password'])) {
$records = $conn->prepare('SELECT id, email, password FROM users WHERE email = :email');
$records->bindParam(':email', $_POST['email']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
$message = '';
if (count($results) > 0 && password_verify($_POST['password'], $results['password'])) {
$_SESSION['user_id'] = $results['id'];
header("Location: /php-login");
} else {
$message = 'Lo sentimos, no tienes autorizacion';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Acceso</title>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<?php require 'partials/header.php' ?>
<?php if(!empty($message)): ?>
<p> <?= $message ?></p>
<?php endif; ?>
<h1>Acceso Solo Personal Autorizado</h1>
<span> <a href="signup.php">Registrate</a></span>
<form action="login.php" method="POST">
<input name="email" type="text" placeholder="Introduce tu correo">
<input name="password" type="password" placeholder="Introduce tu contraseña">
<input type="submit" value="Enviar">
</form>
</body>
</html>