34702-vm/login.php
2025-10-05 21:53:53 +00:00

70 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once 'header.php';
require_once 'db/config.php';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($email)) {
$errors[] = 'E-posta zorunludur.';
}
if (empty($password)) {
$errors[] = 'Şifre zorunludur.';
}
if (empty($errors)) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['loggedin'] = true;
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_name'] = $user['name'];
$_SESSION['role'] = $user['role'];
header('Location: /dashboard.php');
exit;
} else {
$errors[] = 'Geçersiz e-posta veya şifre.';
}
} catch (PDOException $e) {
$errors[] = "Veritabanı hatası: " . $e->getMessage();
}
}
}
?>
<div class="container">
<h1>Giriş Yap</h1>
<?php if (!empty($errors)):
?>
<div class="errors">
<?php foreach ($errors as $error):
?>
<p><?php echo htmlspecialchars($error); ?></p>
<?php endforeach;
?>
</div>
<?php endif;
?>
<form action="/login.php" method="post">
<div class="form-group">
<label for="email">E-posta</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Şifre</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit" class="btn">Giriş Yap</button>
</form>
</div>
<?php require_once 'footer.php'; ?>