0

How can I make some images visible to logged-in members only and hide them from non-members? What i am concerned about is that if someone has the link to an image, they would be able to see it. How do I protect the images or the directory from non-members?

Let's say I have an image in a directory: images/sample.jpg

I looked at this question. My needs are the same but couldn't find the solution I was looking for. Host problems securing content in members area folders with .htaccess

Do I need to use .htaccess to protect that directory? If that directory is protected by .htaccess how can the members can see its contents?

EDIT The members will be logged in using the login system that I have created using php.

Community
  • 1
  • 1
azula
  • 56
  • 12
  • In the provide question, they store the image in the DB, are you willing to do so? Do you have a "real" login or it's just an .htaccess login? – ssbb Aug 10 '16 at 09:48
  • I can store the images in the DB but then how can I display them in `php` without giving their name? The only way that I know to link images in `php` is to do this: `` This way I'll be displaying my directory `images` and then anyone can copy the entire directory. – azula Aug 10 '16 at 18:08

1 Answers1

1

In your situation, I would store the picture in the DB. Then use the script in this resolve question : How to retrieve images from MySQL database and display in an html tag

At the begining of the script getImage.php. Just add a test to check if the uer is connected (Session/cookie/whatever you use for your user).

I have the feeling it's not the best so I will be glad if someone else propose a better solution, but at least It do the job. (Ps: the SQL code is a bit old & maybe deprectaed, the purpose is here)

Community
  • 1
  • 1
ssbb
  • 1,921
  • 2
  • 21
  • 42