I really don't get it. I don't understand how .htaccess, php and HTTP work together within the topic http-authentication.
how can this be achieved: I have a folder where i want to prevent access to unauthorized people. in this folder i have images, for example, and if the user is authorized, the image should be displayed, if not he should get the possibility to enter a username and password for this one request.
do i need an .htaccess file, that redirects to a php file, that checks and handles the authentication and sends appropriate headers and also outputs the requested file?
or must i do something else? am i to solve this completely different?
Only if you use the first of the above approaches. Even then, you are usually better off putting the configuration in your main server config (it is more efficient).
If you go with the second approach, you would generally
include
your authentication code at the top of each page that needs authenticating. (For a simple approach anyway, MVC approaches tend to have a more modular means of doing things).