1. Explain how to prevent CSRF attacks in PHP forms.
To prevent CSRF, generate a random token, store it in the session, and include it as a hidden form field. Verify the token when the form is submitted. If it doesn’t match, reject the request.
// Generate token $_SESSION['token']=bin2hex(random_bytes(16));