Hi uzzikie,

the answer is in your question :). You could write a CGI script that takes two parameters as input: the resource to get (e.g. sample.jpg) and a passcode of some sort (e.g. abcdefg). Your passcode could for example be based on the date, based on the user session (identified by a cookie sent earlier), on the number of camels that fit through the eye of a needle on any given day etc. The idea is that you only get the passcode if you access the image through a link somewhere else on your website. This requires that the rest of your website is somewhat dynamic, as it needs to generate (correct) passcodes on the fly.

To actually protect your resources from direct access, you have to intercept the URL's and rewrite them to use your CGI script. If you are using Apache, you can do this with its URL rewriting engine. You'd have to rewrite http://a.com/camel.jpg?42 to http://a.com/cgi-bin/camel_keeper.cgi?camel.jpg&42 or something like that. camel_keeper.cgi is the cgi script described above. For more information on Apache and URL rewriting, visit the Apache documentation site.

So, to summarise, you need to:

* come up with a system to generate non-trivial passcodes

* Rewrite your site in a dynamic fashion so it generates those passcodes in it's links to internal resources

* Write a script that checks the passcode on resource access

* Put in a URL rewriting rule to make sure all resource requests pass through your script

CU
Robartes-


In reply to Re: restricting public access to images by robartes
in thread restricting public access to images by uzzikie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.