There was a problem loading the comments.

I have created an include file that contains a username and password for a database. How do I prevent people from accessing that file directly?

Support Portal  »  Knowledgebase  »  Viewing Article

  Print
Protecting PHP Includes. In order to create a PHP file that is inaccessible from the WWW, please follow these instructions.

[list]
[*]Create a directory within your public_html directory
[*]Password protect the directory
[*]Add the files that you do not want to be accessible to the protected directory. As PHP accesses files internally, it ignores password protected directories. [*]However, if anyone tried to directly access those files from an external source, they would be prompted for a username and password.

An alternative method would be to store the file outside of the web root. If you have a script located at:

/home/sites/yoursite.com/public_html/thescript.php

You could place your database connection file here:

/home/sites/yoursite.com/dbconnect.php

In 'thescript.php', you would have this line:

include('/home/sites/yoursite.com/dbconnect.php');

Thus, keeping it away from the web.

Share via
Did you find this article useful?  

Related Articles

© Eco Web Hosting