Norse
Norse

Reputation: 5757

How to verify JQuery/AJAX referer to prevent CSRF?

if ($_SERVER['HTTP_REFERER'] == "????")

What would the HTTP_REFERER be if this page was reached by a JQuery $.post request?

Upvotes: 2

Views: 3809

Answers (1)

Muhannad A.Alhariri
Muhannad A.Alhariri

Reputation: 3912

try

strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')

Note That not all servers provide this variable

and you can read this Detecting Ajax in PHP and making sure request was from my own website

Upvotes: 4

Related Questions