SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php/mysql authentication site...protect images?

    Hi,

    I wrote a user authentication script that checks the database to validate users. All my php pages are protected however, how can I protect the images from being viewed by those who do not log in? I need to be able to do it without using .htaccess.

    Any ideas would be appreciated.

    Thanks
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Learn the fastest growing martial art
    Women's Self-Defense - Courses and DVDs available

  2. #2
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats fairly simple
    you can use your user login script

    i presume your using sessions or whatever
    just use
    if(session_is_registered[blah]){
    $images = 1;
    }

    then use
    if($images == 1){
    <img src = blah blah>
    }
    with each image
    there's probably a much easier way of doing it, but i'm tired atm

  3. #3
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually you could probably write a function for it :-]
    lets say your image name is http://www.yoursite.com/images/4.jpg
    you could write a simple function to do what i said in the last post, and save yourself writing it multiple times and just use
    $img1 == http://www.yoursite.com/images/4.jpg;
    functionname($img1);
    which could then do the little check and echo/print the html code to the browser or not
    or you could go realy OTT and write a class :-]

  4. #4
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry Gryff, that will not protect against someone access the images like this:

    http://www.site.com/images/image.gif


    The only way to protect the images without using .htaccess would be to put the images in a directory outside the web directory tree. Access your images with a releative path, in your protected scripts:

    example:
    <img src="../../image.gif">




    Cheers.

  5. #5
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    true foto, but i wasnt thinking of that sort of thing, i just figured he wanted to restrict access to images unless your a registered user, so you register :-]
    a *get more users* type of thing

  6. #6
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gryff, your script is otherwise useful, if not for snooping visitors.



    Cheers.

  7. #7
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just realised i can use the function/class i just thought up ( ok so its prolly been done before ) i need to use later on in one of my projects
    just one more reason why sitepoint & there forums rock so much :-]

  8. #8
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Here is what I put in my page:

    <img src="/usr/local/apache/data/photos/august18/images/1.jpg">

    When I try to view it is trying to display this:

    http://mysite.com/usr/local/apache/d...8/images/1.jpg

    What change do I need to make?

    Thanks for the input!
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Learn the fastest growing martial art
    Women's Self-Defense - Courses and DVDs available

  9. #9
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    /usr/local/apache/data/photos/august18/images/1.jpg

    is the absolute path to the picture on your site. It can not be accessed in that way from a web browser. I gather "data" is the web directory, then you should input this to access the picture through your web browser:

    http://mysite.com/photos/august18/images/1.jpg

    Hope this helps.




    Cheers.

  10. #10
    SitePoint Member
    Join Date
    Aug 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was hoping to be able to put my images below root. I guess that's not an option. I need to make sure unauthorized users can't view them. Each directory of images is numbered 1.jpg, 2.jpg, etc...so it would be very easy for someone to figure out how to view the images.

    Any other solutions?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •