How can PHP be used to manipulate form submissions to remove the question mark in the URL?

When a form is submitted using the GET method, the form data is appended to the URL with a question mark. To remove the question mark from the URL, you can use PHP to process the form submission, retrieve the form data, and then redirect to a new URL without the question mark.

<?php
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $formData = $_GET;
    // Process the form data here
    
    // Redirect to a new URL without the question mark
    $newUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    foreach ($formData as $key => $value) {
        $newUrl .= $key . '=' . $value . '&';
    }
    $newUrl = rtrim($newUrl, '&');
    header('Location: ' . $newUrl);
    exit();
}
?>