php – How to save form data only if it comes from a certain site?

Question:

Hi, I have a form that is being used on another site and saving it in my database, through a php action that is on my server. But I would just like to save the data if the form comes from this site's domain. How can I do it?

Answer:

You can check the sending domain like this:

$_SERVER["HTTP_REFERER"]; // http://www.exemplo....

But I have to warn you that this is an editable parameter in the request, you can 'fake' it:

if($_SERVER["HTTP_REFERER"] != 'url autorizado') {
    echo 'URL inválido';
    die();
}
Scroll to Top