I have .php files that make includes of other files, and AJAX scripts that need to make requests to other .php documents.
For example, Document X.php has an AJAX script that sends a request to a B.php document and brings some information. Obviously, being ajax with what is being worked on, the route it points to can be seen from the source code, and anyone who sees the route and accesses it will receive the information that ajax returns.
In these cases, as ajax sends a request with form data, I can see if that request is empty or not with isset and depending on that return the content or not show it.
However, I also have AJAX scripts that only bring information from an .php file. That is, the file in question goes to a database, and gets a score, and that score I bring it to ajax and I put it in a DIV. But here there is no request for a form, so I can not think of what I could do to show it only through ajax and not if you enter the page in question.
I give an example:
<!-- Funcion para AJAX -->
<script>
$(document).on('ready',function(){
$('#boton').click(function(){
$.ajax({
type: "POST",
url: "Reto.php",
data: $("#form").serialize(),
success: function(data)
{
$('#Resultado').html(data);
}
});
$.ajax({
type: "POST",
url: "../Nav/Act/Puntos.php",
success: function(data2)
{
$('#act1').html(data2);
}
});
$.ajax({
type: "POST",
url: "../Nav/Act/Errores.php",
success: function(data3)
{
$('#act2').html(data3);
}
});
});
});
</script>
<!-- Fin -->
The first request sends information $ _ POST ['value1'] etc ... So to prohibit or not access through URLS, I simply verify that this array is not empty, and if it is I deny the data.
But what about the other two AJAX requests? They are not sending data by any form, they are simply extracting data from some documents .php
One solution I can think of is to have hidden forms, but I see it very sloppy.
I was also wondering if it is possible that the .php documents could have particularities such as classes, (private, public) so that it can only be accessed by code and not by a URL. (Private methods can only be accessed by other methods, but not from the object).
Thanks for the help!