If this request is POST in PHP you can do it first of all:
if($_SERVER['REQUEST_METHOD'] == 'POST'){
// Todo seu código
}
This way by GET it will not be able to access the URL through the browser’s address bar. But I’m seeing other ways too, since someone can make a CURL POST in that URL.
To verify that the request is AJAX:
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// É Ajax, faça seu código aqui.
}
It would be good your autocomplete
make the POST request.
It’s hard to think through all the checks, there will always be a way to circumvent the lawsuits. Avoid what you know and don’t worry so much about other things.
Backup exists for this. Restore also, which is more important than the backup in itself.
Your code via POST and to send more parameters in the POST:
In the parameter data
you define more variables. Remembering that the term
is the past for PHP to search.
$("#birds").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
url:"Busca/Cadastros.php",
data: {
term: request.term,
outra_variavel: valor_outra_variavel
},
success: response,
},
},
width: 500,
multiple: false,
matchContains: true,
formatItem: formatItem,
formatResult: formatResult
});
to the autocomplete he makes
get
orpost
in that file.?– novic
he’s doing get
– Hugo Borges
Impossible. If JS accesses, direct access is always possible.
– Bacco
Is there any way to block this page via htacess to respond only to my server’s ip?
– Hugo Borges
or I can change the method.
– Hugo Borges
It is not your server who accesses the script, it is the user’s browser.
– Bacco
@Bacco has shapes yes, one of them is already restricting to
post
only accepting request from the same site.– novic
@Virgilionovic nothing prevents me from ordering a post other than by page. Everything that JS accesses, the user accesses direct. No exception. Every header is generated on the client side, there is no way to differentiate a true request from a false one. The most you can do is trick curious (curious do not know how to do this, simulate requests).
– Bacco
@Bacco but, I can block the type of request!!! and by ip!
– novic
but if I restrict to that post only accept request from the site itself, this does not resolve?
– Hugo Borges
@Hugoborges the site does not require, who requests is the user’s browser. You can only hinder, but there is no way to prevent.
– Bacco
@Bacco got it, damn it.
– Hugo Borges
@Hugoborges I don’t have much more to help, I think you already understand that the problem is that you have to trust what the browser is sending. What you can do is other things, like limit the number of requests and return per IP per hour for no one to download your entire base at once. Large sites like the post office can not avoid bots, imagine "deadly" nodes. Qq way, use post. tokens etc can help amaze curious. At least the listener does not take the data. But qq one who knows how to use a CURL or a basic socket simulates all this.
– Bacco
@Bacco got it, well I have to try my best to find a solution around it. Thank you very much for your help.
– Hugo Borges