Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.
I'm working on a site where are scripts are loaded through index.php What is the best way to prevent people from accessing other scripts on the site directly?
I'm currently using something like this:
Use mod_rewrite to redirect all requests to index.php (except maybe image files & css files). In your index.php file, you can check in $_SERVER what page he person was actually requesting and go from there.
Also, PHP_SELF may not always be set so it's not 100% safe to use. In most cases you can accomplish the same with $_SERVER['SCRIPT_NAME']
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Ideally, you would store sensitive scripts outside the document root so they could not be accessed over HTTP. If your host does not give you access to such a directory, you can put your scripts in a private directory which is password-protected.