0

I am new to PHP so don't know if there is any alternative to require_once(). My issue is: currently I am including database configuration file on almost each and every file which needs to connect with database using require_once(). I don't want to include my configuration file on each and every file because it may cause some security risk. Any kind of help would be apriciated. Thanks in advance.

4
  • 5
    What sort of security risk? If you need the data, you need to include it (or use environment variables, which will be more of a pain to set up)! Commented Sep 4, 2012 at 13:33
  • 1
    require_once() doesn't just display the source code in the browser, as though it were HTML. There is no security risk here, unless you echo the secure data (which only a fool would do). Commented Sep 4, 2012 at 13:35
  • Thanks for the reply, I was just worried about if someone able to hack any of my file, it will put my whole site into risk although I am trying every possibility which keeps me out of this. Thanks Matt. Commented Sep 4, 2012 at 13:44
  • 1
    setup your server right right and put sensitive files outside document root, because you try to fix the problem in wrong place. Commented Sep 4, 2012 at 13:52

1 Answer 1

3

You may use the php.ini setting auto_prepend_file to automatically include files when the php process is started.

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

1 Comment

Thanks, I was just looking for something like this.

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.