Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Restricting File Access. HtAccess?

Featured Replies

Hi Guys,

 

I have built an ecommerce solution however I have a text file that contains "senstivie" informaiton. I need to access the text file in order to read its ocntents, however i dont want people to be bale to just access the file via a URL such as /incs/settings.txt in a web browser.

 

Whats the best way to do this? I know I could do this with htacess by redirecting the url away from the file however, this will then not allow me to read it?

 

Any help would be appreciated..

 

Thanks In Advance

best way is to not put it in the public folder that way no one without file system access can view the files.... my system only has 3 files in the public folder with one of them being the .htaccess file

  • Author

best way is to not put it in the public folder that way no one without file system access can view the files.... my system only has 3 files in the public folder with one of them being the .htaccess file

 

Thanks Snider DK,

 

But how would I go about this? Basically i want to be able to read the file but not the public. I've had an idea that via ht.access I could please a secret key on the text file i.e 1234.

 

So if you visit settings.txt you get redirect as you will need to go to seetings.txt?secret=1234 in order to access.

 

What do you think?

so if you have a cpanel server for example the folder path to the public folder would be

 

/home/ACCOUNT-NAME/public_html

 

you have the file in a folder accessible in the public root so

 

/home/ACCOUNT-NAME/public_html/incs/settings.txt

 

what i would do is to move incs to a new location

 

/home/ACCOUNT-NAME/incs/settings.txt

 

so say you have a php script in the public_html folder called edit-settings.php say from that script to access the txt file you would use this code

 

$settingsFileLocation = dirname(dirname(__FILE__)).'/incs/settings.txt';

 

the dirname finds the folder path of the current file using the php provided __FILE__ constant, the second dirname finds the folder name holding the folder that has the current file in which would give you "/home/ACCOUNT-NAME"

 

that way you dont need to know any folder paths as long as you know the folder/file you need is just one hop up the file's path.

 

thats the safest way, other than that you can make a new .htaccess file in the incs folder denying access but i would only do that if your going to distribute the application to non developers.

 

hope that helps

 

EDIT: to have the whole application out of the public root requires you to screw with the architecture using a index.php file to sort the system out... its easy with object orientated applications and not so much with procedural types

Edited by SniderDK

  • Author

so if you have a cpanel server for example the folder path to the public folder would be

 

/home/ACCOUNT-NAME/public_html

 

you have the file in a folder accessible in the public root so

 

/home/ACCOUNT-NAME/public_html/incs/settings.txt

 

what i would do is to move incs to a new location

 

/home/ACCOUNT-NAME/incs/settings.txt

 

so say you have a php script in the public_html folder called edit-settings.php say from that script to access the txt file you would use this code

 

$settingsFileLocation = dirname(dirname(__FILE__)).'/incs/settings.txt';

 

the dirname finds the folder path of the current file using the php provided __FILE__ constant, the second dirname finds the folder name holding the folder that has the current file in which would give you "/home/ACCOUNT-NAME"

 

that way you dont need to know any folder paths as long as you know the folder/file you need is just one hop up the file's path.

 

thats the safest way, other than that you can make a new .htaccess file in the incs folder denying access but i would only do that if your going to distribute the application to non developers.

 

hope that helps

 

EDIT: to have the whole application out of the public root requires you to screw with the architecture using a index.php file to sort the system out... its easy with object orientated applications and not so much with procedural types

 

Brill. Lots of food for thought! Thanks!

  • Author

What about using standard Apache file permissions?

 

Hi Richard,

 

The problem is that I want my functions to be ableto access the file whilst I dont want users being able to access the file via a URL.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.