When a valid user logs in or starts a session, create a random token string and place it in a hidden form field. Each time a valid mail is created by a valid user, generate an arbitrary token string and store it in $_SESSION , as well as returning it to the clientโs browser. When the browser makes another request to send Ajax, it should also send this token string, which you are comparing with $_SESSION .
This way you can only make an Ajax entry if your server has authorized it before. It prevents anyone who simply knows the URL of the Ajax handler from sending HTTP requests to it.
source share