modify('+7 days'); $expiresAtFormatted = $expiresAt->format('Y-m-d H:i:s'); // 3. Update the user's record in the database $stmt = $pdo->prepare("UPDATE users SET magic_token = ?, magic_token_expires_at = ? WHERE id = ?"); $success = $stmt->execute([$token, $expiresAtFormatted, $userId]); // 4. Display the generated link if ($success) { // Construct the full URL. In a real environment, use a config for the base URL. $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http"; $host = $_SERVER['HTTP_HOST']; $magicLink = "{$protocol}://{$host}/employee_welcome.php?token={$token}"; echo "
You can share this link with the new employee or click the button below to open it directly. It is valid for 7 days.
"; echo "Open Employee View in New Tab"; echo "Or, manually copy the link:
"; echo ""; } else { echo "Could not generate the magic link. Please try again.
"; }