Files
billReminder/views/auth/register.php

43 lines
1.6 KiB
PHP

<?php
// Check if the user is already logged in
if (isset($_SESSION['user_id'])) {
// Redirect to the dashboard if the user is already logged in
header('Location: /dashboard');
exit;
}
// Include error handling
$error = $_SESSION['error'] ?? '';
unset($_SESSION['error']); // Clear the error after displaying
$content = function () use ($error) { ?>
<div class="row justify-content-center">
<div class="col-md-6">
<h2 class="mt-5">Register</h2>
<?php if ($error) : ?>
<div class="alert alert-danger" role="alert">
<?php echo htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<form action="/register" method="post">
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
<p class="mt-3">Already have an account? <a href="/">Login here</a>.</p>
</div>
</div>
<?php };
require __DIR__ . '/../layouts/app.php';