sql - Hide Database Login Information in PHP Code -
im total beginner in web programming. im trying create simple website reading data sql database. @ first wrote database password , login directly php code:
<?php $username = "login"; $password = "pw"; mysql_connect("server", $username, $password); ... ?>
this isn't idea! (much) more "secure" way this? read putting php code seperate file, meaning not main php document of website, , restricting access file. maybe .htaccess file. way go?
the config.php
file , .htaccess
classic/good way go. it's way done cms or frameworks.
as pointed johnp
, can store config.php
outside of public directory, means can't accessed via http. little better security (if don't make mistake .htaccess, there no more risks).
file structure example :
config/
-> configuration fileslib/
-> libraries , utils php filespublic/
-> public pages/files/images...
that way, http://www.your-site.com/ points public/
, there's no way access config. solution implies can change root web directory (or that).
finally, have remember set file readable , writeable apache user only, not (unix file access rights), if gain access server through user, can't read file.
Comments
Post a Comment