Through researching, I discovered two common techniques to prevent clients from accessing libraries directly with a browser:
- Use
.htaccessto keep them out - Define a constant and pass it to included files, included files then checks if the constant exists.
However, just keeping those files out of the document root seems sensible. Is there anything wrong with this approach?
The best thing to do is keep it outside of your docroot. There is no reason to put includes in a directly HTTP-accessible place.
Some shared web hosts are poorly configured and don’t have this option, but most do, and you definitely have this choice on your own server or VPS.