1

currently i am storing connection data in php file. but like recently happen with facebook, that php files were appear on screen without processing , to avoid such scenario is their any other alternative?

4 Answers 4

1

Put your file which contains connection string Eg: connect.php outside the webroot folder.

Sign up to request clarification or add additional context in comments.

2 Comments

i am on shared host the how will i access that file
put the file outside public_html and access the file with relative path ie., ../connect.php
1

If you're that concerned, add an htaccess exception that makes the "connection string" file inaccessible from the web.

RewriteRule /path/to/dbsettings.php /index.php [NC]

I believe that's correct, though little rusty in the htaccess field. Any gurus feel free to correct me.

Comments

0

Store your private connection information in a file outside of your document root folder and use require_once to load it.

That way, if something happens, users cannot go to http://yoursite/db.config.php and download your file.

1 Comment

i am using shared host...so do u mean i need to put file outside public_html folder?
0

Our solution is to keep a tiny my.cnf with just the [client] section defined. Most MySQL connectors have a "read_defaults_file" directive which allows you to use the file directly.

You can then keep that file under security, and the script will fail at that line if the user is not authorized for that information.

If you are using at least php5, mysqli::options does exactly what I describe when MYSQLI_READ_DEFAULT_FILE is specified. On older php versions, it looks like the builtin parse_ini_file will do the trick of parsing.

This approach has the advantage of being compatible with Perl, Python, and C, so that if your database info changes, you just update one file, and all your applications stay in sync.

2 Comments

.ini files is not accessible directly?
.ini files is accessible directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.