In .htaccess, there's no neat solution. In httpd.conf, you can use the RewriteMap directive to call a cgi script to do the lookup, and act based on the returned value. But RewriteMap is not available in the .htaccess context.
Perhaps your needs will be met by using PHP's "auto-prepend" function to automatically include the call to your lookup script on all of your php pages. See [webmasterworld.com...]
I'm a fish out of water here, I know next to nothing about how servers work.
I had a look at the thread you suggested begun by mvl22, but I can't say I understand much.
As it is now I can simply call the script up with an "include" command in each of the (very many) files. If I understand correctly then there is a way to configure the server to automatically attach this script either before or after the rest of the files. In layman's terms, what do I need to do and where do I need to do it to avoid manually placing "include" on every file?
I asked the tech guy who takes care of the server to set it so it would parse .html files looking for php code (otherwise I'd have to rename the files and would thus compromise all the SEO work done).
Would using "auto-prepend" in this case work for the .html files as well?