I have a lot of php
files updating my database, but I want these to only work when called in my code (usually by ajax).
Now, if I put the URL of the php
file, it updates the database, and if I put ajax code in inspect element, the database updates.
I don't want people messing around with information that is not supposed be changed by them.
How do I fix this?
Ex.
In one of the files I add 1 to a db value. If I put the link to this file in the browser, it adds one. If I put ajax to go to this link, it also updates the DB. This is really bad for security on the site.
Edit: i'm trying to implement the top rated answer but I'm getting the error:
Unexpected token '.'. Expected a ':' following the property name 'myreq'.
Here is my code:
var myreq = new XMLHttpRequest();
$.ajax({
headers: {
myreq.setRequestHeader("X-Requested-With", "XMLHttpRequest");
}
url: 'http://myurl.php',
data: {},
type: 'post',
success: function(output) {
}
});
I might have to put the myreq part under beforeSend instead of headers but idk, I'm new to this.