I am new to using AJAX and I just followed the tutorial to get some information from my database using AJAX and display it on the page. There is a line where I call the php script, where the database query is executed, and the result is displayed. I'm a little worried that since the file name is visible in the external interface, and only the goal is to directly output the database results, this may pose a security problem. Is there a way to protect this file and make sure that it launches the request only when called through ajax script?
Here is the ajax code bit (note the line "somefile.php"):
ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxResponse = ajaxRequest.responseText; element.innerHTML = '<h2>' + ajaxResponse + '</h2>'; } } ajaxRequest.open("GET", "somefile.php", true); ajaxRequest.send(null);
Thanks for any answers.
source share