<?php
// refresh_captcha.php
session_start();

// Generate new CAPTCHA code
function generateNewCaptcha() {
    $captcha_code = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 6);
    $_SESSION['captcha'] = $captcha_code;
    return $captcha_code;
}

$new_captcha = generateNewCaptcha();

// Return the new CAPTCHA code as JSON
header('Content-Type: application/json');
echo json_encode([
    'success' => true,
    'captcha' => $new_captcha
]);
exit;
?>