Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6212531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:31:54+00:00 2026-05-24T06:31:54+00:00

Right now I am using base64 to control who has access to images on

  • 0

Right now I am using base64 to control who has access to images on my website. I store these images outside of the webroot directory so no one has direct access to them. I then determine who has access to these images by what records they have access to in a postgresql database. Basically if they can query record “a” then they can see picture “a”.

if (file_exists($pic)) {
    $imgbinary = fread(fopen($pic, "r"), filesize($pic));
    $picbase64 = "data:image/gif;base64," . base64_encode($imgbinary);
    echo('<img src="' . $picbase64 . '" />');

How can I use readfile instead of base64 while still maintaining my security? For example when using the readfile method to deliver the images to the clients browser this requires me to use the $_GET method to send a variable to a php script that has the readfile and header type that then displays the images on the clients browser. The problem is anyone can look at the html source and see the <img src=phpscript.php?imagename=foo.jpg /> and then call the script in their browser with any argument they like http://www.hostname/phpscript.php?imagename=bar.jpg . With the base64 method I am currently using this is not possible since I do not need to have a separate script to process my images that takes a $_GET argument, instead the images are embedded directly in the html page.

Thanks for any help!

-Edit-
Sorry guys I failed to mention that there is also anonymous access allowed and certain information is public. Meaning if you are not authenticated and you can read record “a” you can also see image “a”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:31:54+00:00Added an answer on May 24, 2026 at 6:31 am

    The substantive difference between what you’re doing now and what you need to do is to send the files over multiple requests. This requires authenticating or otherwise remembering the user between requests.

    What you have right now is:

    if (file_exists($pic)) {
        // do stuff
    }
    

    And what you need is:

    if (file_exists($pic) && user_has_image_permission($pic)) {
        // do stuff
    }
    

    So the details you need to settle on are the logic behind the user_has_image_permission() function.

    If you need this to be secure, I’d be inclined to approach this with sessions, but you could also use cookies.

    If you don’t mind trading some security for a bit of simplicity, you could use some sort of “url pass phrase”, like those commonly used to share documents and files in web services like “anyone with the link” in Google Docs, AWS, private RSS feeds, etc.

    Finally, you could use a solution completely outside of PHP, based on http authentication. In Apache, this takes the form of Access Control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using a Java EE application and we are right now using Informix
Right now I am using std::pair to represent a 2d point in c++. However,
Right now I currently using transactional replication with updatable subscription. Is there any ways
Right now I'm using a few scripts to generate files that I'm including as
Right now I'm using the following: export CFLAGS=-O2-isysroot/Developer/SDKs/MacOSX10.5.sdk -arch i386 -I/sw/include/ export LDFLAGS=-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk,-L/sw/lib/ sudo
Right now I'm using JFreeChart in order to create a dynamic chart. However the
Right now I'm using: r.forEach( function (el) { el.scale(0.5, 0.5, 0.0, 0.0); }); to
Right now I am using this on my string substr($row->review[$i] , 0, 120) but
Right now I am using the maven-javadoc-plugin to attach the Javadoc to .jar artifacts
Right now I am using j security check and md5 to authenticate my jsp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.