I was wondering if there is a way to check if a PHP page was called by an Ajax request. I have a page that shows a form for update some data on database (update.php) but I want to make it accessible only if it was called by a page called "change_image.php", because I won't show the form if called by direct link, as it will be without CSS and javascript, because they are included in the first page (update.php).
I saw this answer on StackOverflow, but it is without explanation and I don't know if it is the right way to do that: Link to answer
The code of the answer is that:
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
/** Yes, it was an ajax call! */
/* I can call create_mosaic() function here
after checking if images have been loaded*/
}