Jump to content

Recommended Posts

I have a script located in http://www.mysite.com/script/, that reads the content of a xml configuration file, placed in the same directory. "config.xml" it's a configuration files of vital importance for the script to work properly. It contains user and password of the mysql database, and other important informations too, that shoul be visible ONLY to the script. The problem is that config.xml is readable by everybody by typing http://www.mysite.com/script/config.xml in the browser. So, I need to protect it, and I've thought to do it using .htaccess. I've created a .htaccess file in the folder, and this is his content:

 

<Files config.xml>

order allow,deny

deny from all

</Files>

 

Now, the result is that the file is inaccessible to all, INCLUDING THE SCRIPT, that doesn't work anymore. Is there a way to make the file readable only by the script? Even without using .htaccess. This is driving me crazy. Thanks in advance for your answers.

Link to comment
https://forums.phpfreaks.com/topic/132807-using-htaccess-to-deny-access-to-a-file/
Share on other sites

You should be reading or including the file using a file system path and not a URL.

 

Using a URL causes your web server to make a separate http request back to your web server to fetch the contents of the file. This takes about 100 times longer than if you read the file through the file system.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.