George Irimiciuc
George Irimiciuc

Reputation: 4633

Redirect included files

I have this file which stores my db info

<?php
$DBServer = 'this';
$DBUser   = 'is';
$DBPass   = 'my';
$DBName   = 'secret';
?>

And it is included where I need it to connect to the db. My question is, how can I prevent users from going to mywebsite/db_info.php ? I know it displays a blank to them and they don't have access to the info, but I'd like to redirect them to the index page. The problem comes when this file being included in another one, it will always redirect to the index page when used(when I will connect to the db).

Upvotes: 0

Views: 36

Answers (2)

felipegallo
felipegallo

Reputation: 22

First, what is the point to redirect a file with important information like database access? No users should have access to this file, or even his name and path.

There are some approaches you can choose, one security option it is to allocate your db_info.php file outside the public root of your domain. Exemple:

yourdomain.com = /home/user/www/

your file should be: /home/user/db_info.php (or outsite /www/ folder!)

Upvotes: 1

kiks73
kiks73

Reputation: 3758

With apache, You can put your file in a separate folder within a .htaccess file with this content:

Order deny,allow
Deny from all

So you will have:

/yourPrivateFolder/.htacces
/yourPrivateFolder/db_info.php

This will prevent external access to your file

Upvotes: 1

Related Questions