<?php if ($message): ?>
<div class="message <?php echo strpos($message, 'success') !== false || strpos($message, 'sent') !== false || strpos($message, 'registered') !== false ? 'success' : 'error'; ?>">
<?php echo htmlspecialchars($message); ?>
</div>
<?php endif; ?>
<form method="POST" action="">
<div class="form-group">
<label for="email">Enter your email to subscribe:</label>
<input type="email" name="email" id="email" required>
</div>
<button type="submit" id="submit-email">Submit</button>
</form>
<!-- Verification Code Form - Always visible -->
<form method="POST" action="">
<div class="form-group">
<label for="verification_code">Enter verification code:</label>
<input type="text" name="verification_code" id="verification_code" maxlength="6" required>
</div>
<button type="submit" id="submit-verification">Verify</button>
</form>
<p><a href="unsubscribe.php">Unsubscribe from XKCD updates</a></p>
</body>
</html>
<?php
session_start();
require_once 'functions.php';
$message = '';
$showVerificationForm = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['unsubscribe_email']) && !isset($_POST['verification_code'])) {
// Handle unsubscribe email submission
$email = filter_var($_POST['unsubscribe_email'], FILTER_VALIDATE_EMAIL);
if ($email) {
// Check if email exists in registered emails
$file = __DIR__ . '/registered_emails.txt';
if (file_exists($file)) {
$emails = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if (in_array($email, $emails)) {
$code = generateVerificationCode();
$_SESSION['unsubscribe_verification_' . md5($email)] = $code;
$_SESSION['pending_unsubscribe_email'] = $email;
if (sendUnsubscribeConfirmationEmail($email, $code)) {
$message = 'Unsubscribe confirmation code sent to your email!';
$showVerificationForm = true;
} else {
$message = 'Failed to send confirmation email. Please try again.';
}
} else {
$message = 'Email not found in our subscription list.';
}
} else {
$message = 'No subscribers found.';
}
} else {
$message = 'Please enter a valid email address.';
}
} elseif (isset($_POST['verification_code'])) {
// Handle unsubscribe verification code submission
$code = $_POST['verification_code'];
$email = $_SESSION['pending_unsubscribe_email'] ?? '';
$sessionKey = 'unsubscribe_verification_' . md5($email);
if (isset($_SESSION[$sessionKey]) && $_SESSION[$sessionKey] === $code) {
unsubscribeEmail($email);
$message = 'Successfully unsubscribed from XKCD updates!';
unset($_SESSION[$sessionKey]);
unset($_SESSION['pending_unsubscribe_email']);
$showVerificationForm = false;
} else {
$message = 'Invalid verification code. Please try again.';
$showVerificationForm = true;
}
}
}
// Check if we should show verification form based on session
if (isset($_SESSION['pending_unsubscribe_email']) && !$showVerificationForm && empty($message)) {
$showVerificationForm = true;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Unsubscribe from XKCD</title>
<style>
body { font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }
.form-group { margin-bottom: 15px; }
input[type="email"], input[type="text"] { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; }
button { background-color: #dc3545; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; }
button:hover { background-color: #c82333; }
.message { padding: 10px; margin: 10px 0; border-radius: 4px; }
.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
</style>
</head>
<body>
<h1>Unsubscribe from XKCD Updates</h1>
<?php if ($message): ?>
<div class="message <?php echo strpos($message, 'Successfully') !== false || strpos($message, 'sent') !== false ? 'success' : 'error'; ?>">
<?php echo htmlspecialchars($message); ?>
</div>
<?php endif; ?>
<!-- Unsubscribe Email Form - Always visible -->
<form method="POST" action="">
<div class="form-group">
<label for="unsubscribe_email">Enter your email to unsubscribe:</label>
<input type="email" name="unsubscribe_email" id="unsubscribe_email" required>
</div>
<button type="submit" id="submit-unsubscribe">Unsubscribe</button>
</form>
<!-- Verification Code Form - Always visible -->
<form method="POST" action="">
<div class="form-group">
<label for="verification_code">Enter verification code:</label>
<input type="text" name="verification_code" id="verification_code" maxlength="6" required>
</div>
<button type="submit" id="submit-verification">Verify</button>
</form>
<p><a href="index.php">Back to subscription</a></p>
</body>
</html>
change the styles without changing the functionality and functions. make ui styles of comic theme .make it more clean and beautifull
I'll help you redesign the XKCD subscription system with a clean, comic-themed UI while preserving all the functionality. Here are the updated files with improved styling:
index.php
unsubscribe.php
The functionality remains exactly the same - all PHP logic, form handling, and session management are preserved. Only the visual presentation has been enhanced with a clean, modern comic theme that reflects the XKCD brand!
change the font and remove the emojis.make the form clean and more good looking . change the background as comic designs and some quotes about comics . use fonts of very descent and company standard
I'll redesign the XKCD subscription system with professional fonts, clean forms, and comic-themed backgrounds with quotes. Here are the updated files:
index.php
unsubscribe.php
The design now maintains the comic theme through background elements and quotes while presenting a clean, professional interface that would fit well in any corporate environment. All functionality remains exactly the same!