I have a directory containing data that should not be world-accessible until a certain date.
The directory, naturally, should not be directly world-readable with a web browser. I currently solve this with .htpasswd and .htaccess.
However, there is a world-readable .php file one directory level up. The PHP file, based on the date, conditionally generates basic HTML tags (e.g., <img .../>) that read from the protected directory.
Unfortunately, in my tests, the .php file requires authentication to load the data. My question is whether I’m trying to do something fundamentally impossible, or whether I can tweak it to make it work. Also, if it is possible, are there any additional issues (security or otherwise) that I should know about?
Additional information:
- If possible, I would prefer not to use Javascript.
- PHP 5.3 is available.
- Any other ideas for a solution (I already thought of a cron-job, which I might yet do)?
I’m guessing a problem you might have is if you try to output
<img src="protected.jpg" />even from an unprotected php file, you’ll be able to show the HTML but NOT the image file itself.If i understand correctly what you’re trying to do, you need either :
Edit : proxy example : i can’t seem to find an example online so this is a function i often use when i wish to control access to a file from PHP (for instance this can be sensitive data whose access needs to be verified from $_SESSION or DB values) :
Of course you still need to restrict direct access from .htaccess but in case of a proxy you’ll redirect all requests to your unprotected proxy script, like this :
And proxy.php would contain something like :