saved emails, gmail, hotmail start, home, landing etc
This commit is contained in:
@@ -9,11 +9,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$confirm_email = trim($_POST['confirm_email'] ?? '');
|
||||
$password = $_POST['password'] ?? '';
|
||||
$age = (int) ($_POST['age'] ?? 0);
|
||||
$dob = $_POST['dob'] ?? ''; // from <input type="date" name="dob">
|
||||
$captcha = $_POST['g-recaptcha-response'] ?? '';
|
||||
|
||||
// Basic validation
|
||||
if (empty($username) || empty($email) || empty($confirm_email) || empty($password) || empty($age)) {
|
||||
if (empty($username) || empty($email) || empty($confirm_email) || empty($password) || empty($dob)) {
|
||||
$errors[] = "All fields are required.";
|
||||
}
|
||||
|
||||
@@ -29,8 +29,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$errors[] = "Password must be at least 6 characters.";
|
||||
}
|
||||
|
||||
if ($age < 16) {
|
||||
$errors[] = "You must be at least 16 years old to register.";
|
||||
// Date of Birth validation
|
||||
if ($dob) {
|
||||
try {
|
||||
$birthDate = new DateTime($dob);
|
||||
$today = new DateTime();
|
||||
|
||||
if ($birthDate > $today) {
|
||||
$errors[] = "Date of birth cannot be in the future.";
|
||||
}
|
||||
|
||||
if ($birthDate < new DateTime('1900-01-01')) {
|
||||
$errors[] = "Please enter a valid birth year (1900 or later).";
|
||||
}
|
||||
|
||||
$age = $today->diff($birthDate)->y;
|
||||
if ($age < 16) {
|
||||
$errors[] = "You must be at least 16 years old to register.";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errors[] = "Invalid date of birth.";
|
||||
}
|
||||
}
|
||||
|
||||
// CAPTCHA validation
|
||||
@@ -55,11 +74,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);
|
||||
$uniqueId = bin2hex(random_bytes(16));
|
||||
|
||||
$insert = $conn->prepare("INSERT INTO users (username, email, password, uniqueid) VALUES (:username, :email, :password, :uniqueid)");
|
||||
$insert = $conn->prepare("INSERT INTO users (username, email, password, dob, uniqueid)
|
||||
VALUES (:username, :email, :password, :dob, :uniqueid)");
|
||||
$insert->execute([
|
||||
'username' => $username,
|
||||
'email' => $email,
|
||||
'password' => $hash,
|
||||
'dob' => $dob,
|
||||
'uniqueid' => $uniqueId,
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user