I have a javascript on my webpage which makes a call to a php file and passes some values to the php file. How can i know for sure that the call to the php file was from the js on my webpage and not directly entering the php url from the browsers address bar?
Share
You’ll want to use check if
$_SERVER['HTTP_X_REQUESTED_WITH']isXMLHttpRequest. That will prevent people from directly typing the URL in their browsers while allowing Ajax requests.You might want to see Do all browsers support PHP's $_SERVER['HTTP_X_REQUESTED_WITH']? for an explanation of what browsers/JavaScript libraries send the
HTTP_X_REQUESTED_WITHheader.