I am a PHP newbie and a have a php security question. Is it possible for somebody to get the source code of a php script file running on a server with default configuration?
What you describe as "default configuration" is a webserver without php installed (or with php disabled). In these cases, it is certainly possible to download the php script.
Make sure php is installed (as it will be on ~100% of production php servers) and/or block access to your configuration file with an .htaccess
file like this:
Order allow,deny
Deny from all
If you want to be extra-tricky (and work even on servers where .htaccess
files are ignored), prefix the configuration file with .ht
, like .ht.config.php
. Most Apache(and some other webserver) configurations will refuse serving files beginning with .ht
. However, in general, the only way you could be sure no webserver serves your file is to move it to a directory outside of the server's document directory. On most hosts you or your php script won't be able to access those though.