April 30, 201115 yr 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
April 30, 201115 yr 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
April 30, 201115 yr 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?
April 30, 201115 yr 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 April 30, 201115 yr by SniderDK
April 30, 201115 yr 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!
May 1, 201115 yr 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