Problem: (somewhat in line with my last post) I needed to run a script in the "background", but I only had the ability to present the script as a .gif.
Solution: actually, I came up with two ways of doing this and both use .htaccess to pull it off.
1) I'm a gif but really I'm a php script
This one is fairly straightfoward. I put my script in a seperate directory, (that doesn't actually include any images!) and renamed it from filename.php to filename.gif (or filename.jpg) (Yes, I know it's not really an image file. Hang in there)
Then, in the htaccess file for JUST THAT FOLDER! (similar to this trick) I added this:
AddType application/x-httpd-php .php .jpg .gif
FYI – in your php file (that now looks like a .gif or .jpg) make sure you don't have any headers/text echoed, and at the end of the file add this to your php code:
header('Content-Type: image/gif');
@readfile( '/SERVERPATH/TO/A/REAL/IMAGE/spacer.gif' );
You can then include the "script" as if it were an image file, it will run the script, but only display a gif to the user.
You can even pass it variables like filename.gif?somevariable=somevalue&anotervariable=anothervalue, but there's another way to do that too without the ugly URL.
2) I'm a gif that's actually a php script super-powered with rewrite
Ok, starting from the beginning. You have your script (filename.php) in a folder, add the following to the .htaccess file in that folder:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/(.*)/spacer.gif /YOURFOLDER/FILENAME.php?somevar=$1&anothervar=$2 [QSA]
Before we continue, I must tell you that I dont' completely understand rewrite rules. There's a LOT of holes in my knowledge. So if you have a better way, PLEASE post it in the comments. I would LOVE to be able to understand what the hell I'm doing. LOL.
OK, moving along. Now you can call your script by actually calling that "phantom" spacer.gif, with the variables in the URL as if they're directories like this:
http://www.yourdomain.com/YOURFOLDER/somevalue/anothervalue/spacer.gif
Again, make sure you have this at the end of you php code in your filename.php:
header('Content-Type: image/gif');
@readfile( '/SERVERPATH/TO/A/REAL/IMAGE/spacer.gif' );