What potential security risks are associated with using $_SERVER['HTTP_REFERER'] to track form submission URLs?

Using $_SERVER['HTTP_REFERER'] to track form submission URLs can pose security risks as this data can be easily manipulated by the user. An attacker could potentially spoof the HTTP_REFERER header to trick the server into accepting a malicious URL as the form submission URL. To mitigate this risk, it is recommended to validate the form submission URL on the server-side using a more secure method, such as storing the expected URL in a hidden form field and comparing it with the submitted value.

// Validate form submission URL
$expected_url = 'https://www.example.com/form-handler.php';

if(isset($_POST['form_url']) && $_POST['form_url'] === $expected_url){
    // Form submission URL is valid
    // Process form data
} else {
    // Invalid form submission URL
    // Handle error accordingly
}