<?php
// login.php
session_start();
require 'db.php'; // Veritabanı bağlantısını sağlayan dosya
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Kullanıcıdan gelen verileri al
$username = trim($_POST['username']);
$password = trim($_POST['password']);
// Kullanıcı adı ve şifre kontrolü
if (!empty($username) && !empty($password)) {
// Kullanıcıyı veritabanında ara
$stmt = $pdo->prepare("SELECT id, password_hash FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$user = $stmt->fetch();
// Şifreyi doğrula
if ($user && password_verify($password, $user['password_hash'])) {
$_SESSION['user_id'] = $user['id'];
header('Location: index.php');
exit();
} else {
$error = "Kullanıcı adı veya şifre yanlış.";
}
} else {
$error = "Kullanıcı adı ve şifre girilmelidir.";
}
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Giriş Yap</title>
<script src="
https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 flex flex-col min-h-screen">
<!-- Navbar -->
<nav class="bg-white shadow-md">
<div class="container mx-auto px-4 py-4 flex justify-between items-center">
<h1 class="text-2xl font-bold text-blue-600">Forum</h1>
<div>
<a href="index.php" class="text-gray-700 hover:text-blue-600 mx-2">Ana Sayfa</a>
<a href="categories.php" class="text-gray-700 hover:text-blue-600 mx-2">Kategoriler</a>
<a href="login.php" class="text-gray-700 hover:text-blue-600 mx-2">Giriş Yap</a>
<a href="register.php" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-500">Kayıt Ol</a>
</div>
</div>
</nav>
<!-- Login Section -->
<section class="container mx-auto px-4 py-8 flex-grow">
<h2 class="text-3xl font-bold mb-4 text-center">Giriş Yap</h2>
<div class="max-w-md mx-auto bg-white p-6 shadow-md rounded-md">
<?php if (!empty($error)): ?>
<div class="bg-red-200 text-red-800 p-4 rounded mb-4"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form action="login.php" method="post">
<div class="mb-4">
<label for="username" class="block text-gray-700">Kullanıcı Adı</label>
<input type="text" id="username" name="username" class="mt-1 block w-full p-2 border border-gray-300 rounded-md" required>
</div>
<div class="mb-4">
<label for="password" class="block text-gray-700">Şifre</label>
<input type="password" id="password" name="password" class="mt-1 block w-full p-2 border border-gray-300 rounded-md" required>
</div>
<button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-500">Giriş Yap</button>
</form>
</div>
</section>
<!-- Footer -->
<footer class="bg-gray-800 text-white py-6 mt-auto">
<div class="container mx-auto text-center">
<p>© 2024 Forum Sitesi. Tüm Hakları Saklıdır.</p>
</div>
</footer>
</body>
</html>
<?php
// register.php
require 'db.php'; // Veritabanı bağlantısını sağlayan dosya
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Kullanıcıdan gelen verileri al
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$password = trim($_POST['password']);
// Kullanıcı adı, e-posta ve şifre kontrolü
if (!empty($username) && !empty($email) && !empty($password)) {
// Şifreyi hashle
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
// Veritabanına kullanıcı ekle
$stmt = $pdo->prepare("INSERT INTO users (username, email, password_hash) VALUES
username, :email,
assword_hash)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':email', $email);
$stmt->bindParam('
assword_hash', $passwordHash);
if ($stmt->execute()) {
header('Location: login.php');
exit();
} else {
$error = "Kayıt sırasında bir hata oluştu.";
}
} else {
$error = "Tüm alanlar doldurulmalıdır.";
}
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kayıt Ol</title>
<script src="
https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 flex flex-col min-h-screen">
<!-- Navbar -->
<nav class="bg-white shadow-md">
<div class="container mx-auto px-4 py-4 flex justify-between items-center">
<h1 class="text-2xl font-bold text-blue-600">Forum</h1>
<div>
<a href="index.php" class="text-gray-700 hover:text-blue-600 mx-2">Ana Sayfa</a>
<a href="category.php" class="text-gray-700 hover:text-blue-600 mx-2">Kategoriler</a>
<a href="login.php" class="text-gray-700 hover:text-blue-600 mx-2">Giriş Yap</a>
<a href="register.php" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-500">Kayıt Ol</a>
</div>
</div>
</nav>
<!-- Registration Section -->
<section class="container mx-auto px-4 py-8 flex-grow">
<h2 class="text-3xl font-bold mb-4 text-center">Kayıt Ol</h2>
<div class="max-w-md mx-auto bg-white p-6 shadow-md rounded-md">
<?php if (!empty($error)): ?>
<div class="bg-red-200 text-red-800 p-4 rounded mb-4"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form action="register.php" method="post">
<div class="mb-4">
<label for="username" class="block text-gray-700">Kullanıcı Adı</label>
<input type="text" id="username" name="username" class="mt-1 block w-full p-2 border border-gray-300 rounded-md" required>
</div>
<div class="mb-4">
<label for="email" class="block text-gray-700">E-posta</label>
<input type="email" id="email" name="email" class="mt-1 block w-full p-2 border border-gray-300 rounded-md" required>
</div>
<div class="mb-4">
<label for="password" class="block text-gray-700">Şifre</label>
<input type="password" id="password" name="password" class="mt-1 block w-full p-2 border border-gray-300 rounded-md" required>
</div>
<button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-500">Kayıt Ol</button>
</form>
</div>
</section>
<!-- Footer -->
<footer class="bg-gray-800 text-white py-6 mt-auto">
<div class="container mx-auto text-center">
<p>© 2024 Forum Sitesi. Tüm Hakları Saklıdır.</p>
</div>
</footer>
</body>
</html>
Login ve register da yaşıyorsan sorunu, login ve registerı atman gerekiyor.
burdalar hocam