A
A
Alexander2019-05-26 18:26:15
PHP
Alexander, 2019-05-26 18:26:15

How to prevent users from accessing a txt file?

There is txt, you need to set such rights in it so that php can continue to write and read it, and the user could not access it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SagePtr, 2019-05-26
@SagePtr

It is safer to keep the file outside the root of the web server, because suddenly the server will have nginx in front of Apache, and there it will be configured to send static files past Apache. As a result, the server will give this file without checking .htaccess.

N
nrgian, 2019-05-26
@nrgian

In the case of a web user, this is done from within your PHP program.
htaccess, what's in your tags - it has nothing to do with it.
Who is a web user, no one except your PHP program made - and does not know.

A
AUser0, 2019-05-26
@AUser0

Put a period in the name of the txt file. For Apache, all files starting with a dot are prohibited from viewing via the web (.htaccess/.htpasswd is an example of this).
If you need to deny access to a local user on a UNIX system, set the permissions to rw-rw---- (0660). And the user/group that Apache is running under so that PHP running under Apache with that user/group has full access to the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question