0

I am working on a music web app. I am adding a feature where there is a button next to each song to delete it from the database. The page will accomplish this by sending a parameter songId to a PHP page that will deal with it. Now, I want to prevent people being able to send POST requests to that PHP page from a remote server. What conditions can I check to restrict the POST request to originate from my music web app only, or localhost.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Tuan Vo
  • 41
  • 1
  • 5

1 Answers1

0
if($_SERVER['REMOTE_ADDR'] != '127.0.0.1' && $_SERVER['REMOTE_ADDR'] != '::1') {
    exit('access denied');
}

However, this will not protect you against CSRF. To prevent a malicious website from creating a form that POSTs to your application when it's submitted (possibly automatically via JavaScript) you need to implement proper CSRF protection through a secret token an attacker website cannot know.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636