125 lines
3.5 KiB
PHP
125 lines
3.5 KiB
PHP
<?php
|
|
// 1. IL PHP SEMPRE IN ALTO (PRIMA DI OGNI HTML/CSS)
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
session_start();
|
|
require '_db_config.php'; // Assicurati che il file si chiami così e che la variabile sia $conn
|
|
|
|
$messaggio_errore = "";
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
// RIMOSSO il controllo su 'email' perché nel form non c'è
|
|
if (isset($_POST['username']) && isset($_POST['password'])) {
|
|
|
|
$user = $_POST['username'];
|
|
$pass = $_POST['password'];
|
|
|
|
// CONTROLLA SE LA TABELLA È 'utente' O 'utenti'
|
|
$sql = "SELECT password FROM utente WHERE username = ?";
|
|
$stmt = mysqli_prepare($conn, $sql);
|
|
|
|
if ($stmt) {
|
|
mysqli_stmt_bind_param($stmt, "s", $user);
|
|
mysqli_stmt_execute($stmt);
|
|
|
|
$risultato = mysqli_stmt_get_result($stmt);
|
|
$riga = mysqli_fetch_assoc($risultato);
|
|
|
|
if ($riga && password_verify($pass, $riga['password'])) {
|
|
$_SESSION['loggato'] = true;
|
|
$_SESSION['utente'] = $user;
|
|
|
|
// Ora il reindirizzamento funzionerà perché non c'è HTML sopra
|
|
header("Location: visualizza_dati.php");
|
|
exit;
|
|
} else {
|
|
$messaggio_errore = "Username o Password non validi!";
|
|
}
|
|
mysqli_stmt_close($stmt);
|
|
} else {
|
|
$messaggio_errore = "Errore nel database: " . mysqli_error($conn);
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Login</title>
|
|
<style>
|
|
/* Il tuo CSS qui (lo stesso che hai postato) */
|
|
body {
|
|
font-family: 'Segoe UI', Arial, sans-serif;
|
|
background-color: #f0f2f5;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
padding: 40px;
|
|
}
|
|
|
|
.box {
|
|
background: #fff;
|
|
padding: 25px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
width: 100%;
|
|
max-width: 400px;
|
|
}
|
|
|
|
input {
|
|
width: 100%;
|
|
padding: 12px;
|
|
margin: 10px 0;
|
|
border: 1px solid #ddd;
|
|
border-radius: 6px;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
button {
|
|
width: 100%;
|
|
padding: 12px;
|
|
background-color: #007bff;
|
|
border: none;
|
|
border-radius: 6px;
|
|
color: white;
|
|
font-weight: bold;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
margin-bottom: 15px;
|
|
text-align: center;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="box">
|
|
<h2>Accedi</h2>
|
|
|
|
<!-- Visualizza l'errore se presente -->
|
|
<?php if ($messaggio_errore): ?>
|
|
<div class="error"><?php echo $messaggio_errore; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" action="login.php">
|
|
<input type="text" name="username" placeholder="Username" required>
|
|
<input type="password" name="password" placeholder="Password" required>
|
|
<button type="submit">Accedi</button>
|
|
</form>
|
|
|
|
<p style="text-align:center; margin-top:15px;">
|
|
<a href="index.php" style="color:#007bff; text-decoration:none;">Torna alla Home</a>
|
|
</p>
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|