Selamın Aleyküm.
Kayıt Olma Sayfası Kodlayalım.
kayit_formu.php
kayit_kontrol.php
Kayıt Olma Sayfası Kodlayalım.
kayit_formu.php
Kod:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Kayıt Sayfası</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-image: url('arkaplan.png'); /* Arka plan resmi burada belirtildi */
background-size: cover;
background-position: center;
}
form {
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
width: 300px;
}
label {
font-weight: bold;
margin-bottom: 8px;
display: block;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
width: calc(100% - 22px);
padding: 10px;
margin-bottom: 15px;
border-radius: 5px;
border: 1px solid #ccc;
}
input[type="submit"] {
width: 100%;
padding: 10px;
border-radius: 5px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.verification {
margin-bottom: 15px;
}
.error-message {
color: red;
margin-bottom: 10px;
display: none;
}
</style>
</head>
<body>
<form method="post" action="kayit_kontrol.php">
<h2>Kayıt Ol</h2>
<?php
if (isset($_GET['error'])) {
$error = $_GET['error'];
echo '<div class="error-message">' . $error . '</div>';
echo '<script>setTimeout(function() { document.querySelector(".error-message").style.display = "none"; }, 5000);</script>';
}
?>
<?php
session_start();
$number1 = rand(1, 10);
$number2 = rand(1, 10);
$operators = ['+', '-', '*'];
$operator = $operators[rand(0, count($operators) - 1)];
$result = 0;
switch ($operator) {
case '+':
$result = $number1 + $number2;
break;
case '-':
$result = $number1 - $number2;
break;
case '*':
$result = $number1 * $number2;
break;
}
$_SESSION['captcha'] = $result;
?>
<label for="username">Kullanıcı Adı</label>
<input type="text" id="username" name="username" required>
<label for="email">E-posta</label>
<input type="email" id="email" name="email" required pattern="^[a-zA-Z0-9._%+-]+@(gmail\.com|outlook\.com)$">
<label for="password">Şifre</label>
<input type="password" id="password" name="password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{8,}" title="En az 8 karakterden oluşmalı, en az bir büyük harf, bir küçük harf, bir rakam ve bir özel karakter içermelidir." required>
<label for="password-confirm">Şifre Tekrar</label>
<input type="password" id="password-confirm" name="password-confirm" required>
<p class="verification">Doğrulama Kodu: <?php echo $number1 . ' ' . $operator . ' ' . $number2 . ' = ?'; ?></p>
<input type="number" id="verificationCode" name="verificationCode" required>
<input type="submit" value="Kayıt Ol">
</form>
<script>
<?php
if (isset($_GET['error'])) {
$error = $_GET['error'];
echo 'document.querySelector(".error-message").style.display = "block";';
echo 'setTimeout(function() { document.querySelector(".error-message").style.display = "none"; }, 5000);';
}
?>
</script>
</body>
</html>
kayit_kontrol.php
Kod:
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordConfirm = $_POST['password-confirm'];
$verificationCode = $_POST['verificationCode'];
$captcha = $_SESSION['captcha'];
if (!preg_match("/^(?=.*[a-zA-Z0-9._%+-]+@(gmail\.com|outlook\.com))/", $email)) {
header("Location: kayit_formu.php?error=E-posta alanı yalnızca gmail.com ve outlook.com adreslerini kabul eder.");
exit;
}
if ($password !== $passwordConfirm) {
header("Location: kayit_formu.php?error=Şifreler eşleşmiyor. Lütfen kontrol edin.");
exit;
}
if ($verificationCode != $captcha) {
header("Location: kayit_formu.php?error=Doğrulama kodu hatalı.");
exit;
}
}
?>