What are the potential security risks of using GET method for deleting data in PHP?

Using the GET method for deleting data in PHP can expose your application to security risks such as CSRF attacks, as the request can be easily triggered by an attacker through a crafted link or image tag. To mitigate this risk, you should use the POST method for data deletion operations, as it requires a form submission and cannot be triggered by a simple link click.

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Perform data deletion operation
    // Example: $id = $_POST['id']; // delete data with id $id
} else {
    // Redirect or display an error message
}