Apache: restrict hotlinking to hosted domains

Miscellaneous Forums/General Discussion/Apache: restrict hotlinking to hosted domains

I know I can use .htaccess to prevent hotlinking from a specific or range of IP addresses, or from a specific referrer, but does anyone know if there's any way to allow hotlinking ONLY if the referrer IP is the same as my server?

i.e. if I hosted www.goodcheapstuff.com and www.mylittlestoner.com and wanted to allow mylittlestoner.com (and other sites hosted on the server) to access particular files on goodcheapstuff.com how might I go about this.

(short of listing all the domains that can access and updating this everytime I add a new one)

resolve the IP within a "toplevel" PHP script within which everything is executed for example

It's not easy to do within a PHP script since the directory structure of the host domain will change, I just want to allow all files on it.

I should have mentioned that I had considered doing some sort of lookup on the domain via a script, but it's not my preferred solution. it would be nice to just say something like:

RewriteCond %{HTTP_REFERER_IP}!^123.123.123.123$ [NC]
RewriteRule [^/]+.*$ - [F]