-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.php
52 lines (44 loc) · 1.49 KB
/
verify.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require 'config.php';
$message = '';
$redirect = false;
if (isset($_GET['token'])) {
$token = $_GET['token'];
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $db_username, $db_password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare("SELECT id FROM users WHERE verification_token = ? AND email_verified = FALSE");
$stmt->execute([$token]);
$user = $stmt->fetch();
if ($user) {
$updateStmt = $pdo->prepare("UPDATE users SET email_verified = TRUE, verification_token = NULL WHERE id = ?");
$updateStmt->execute([$user['id']]);
$message = "Your email has been successfully verified. You will be redirected to the login page in 5 seconds.";
$redirect = true;
} else {
$message = "This verification link is invalid or expired.";
}
} catch (PDOException $e) {
$message = "Error: " . $e->getMessage();
}
} else {
$message = "No verification token provided.";
}
if ($redirect) {
header("refresh:5;url=login.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Verification</title>
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<div class="verification-message <?php echo $redirect ? 'success' : 'error'; ?>">
<p><?php echo $message; ?></p>
</div>
</body>
</html>