prepare("DELETE FROM {$table_prefix}password_reset_tokens WHERE user_id = ?"); $stmt->bind_param('i', $user['user_id']); $stmt->execute(); $stmt->close(); // Insert new token $stmt = $db->prepare("INSERT INTO {$table_prefix}password_reset_tokens (user_id, token, expires) VALUES (?, ?, ?)"); $stmt->bind_param('iss', $user['user_id'], $token, $expires); $stmt->execute(); $stmt->close(); // Build reset link $reset_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['SCRIPT_NAME']) . "/reset_password.php?token=" . urlencode($token); // Send email (for now, just show the link - actual email sending requires mail configuration) $email_body = "Hello {$user['users_login']},\n\n" . "You requested a password reset. Click the link below to reset your password:\n\n" . "{$reset_link}\n\n" . "This link will expire in 1 hour.\n\n" . "If you did not request this reset, please ignore this email."; // Attempt to send email $headers = "From: noreply@" . $_SERVER['HTTP_HOST'] . "\r\n" . "Reply-To: noreply@" . $_SERVER['HTTP_HOST'] . "\r\n" . "X-Mailer: PHP/" . phpversion(); $email_sent = @mail($user['users_email'], "Password Reset Request", $email_body, $headers); logger("Password reset requested for user: {$user['users_login']} (email sent: " . ($email_sent ? 'yes' : 'no') . ")"); if ($email_sent) { $message = "Password reset instructions have been sent to your email address."; } else { // If email fails, show the link directly (development mode) $message = "Password reset link generated. In production, this would be emailed to you.

" . "For testing, use this link: Reset Password"; } } else { // For security, don't reveal if user exists or not $message = "If an account exists with that username or email, password reset instructions have been sent."; logger("Password reset requested for unknown identifier: $identifier"); } } } // Close database connection mysqli_close($db); ?> Forgot Password - GameServers.World

Forgot Password

Enter your username or email to reset your password