What I always did is create a folder for PHP scripts are called by AJAX requests, but I wanted to find out, what is a common practice to do it?
What is usual location to put all the request scripts, and are they usually written in one .php file, or is it better to split them in several files? For sure there must be recommendations how to do it secure and better.
Thanks in advance!
I don’t think there is any specific way that would be significantly more common than the others. If you’re using a framework, it may have it’s own best practices and coding conventions you should use. Also, if you’re working with a team, they may have some rules of their own.
As long as your handlers are otherwise secure, it won’t matter how they are organized on the file system. If you have lots of handlers, you may want to split them to logical parts – one PHP file for handling the shopping cart, one for search autocomplete, and so on.
Storing all the AJAX handlers in the same directory is pretty much a matter of preference. It could also be logical to keep them in the same directory as the feature they are related to, like
/users/ajax.php.