kornesh kornesh - 1 month ago 14
PHP Question

What in the world of facebook is rsrc.php?

http://static.ak.fbcdn.net/rsrc.php/117600/css/base.css

http://static.ak.fbcdn.net/rsrc.php/z4HBM/hash/3krgnmig.swf

http://b.static.ak.fbcdn.net/rsrc.php/z23ZQ/hash/3ls2fki5.xml

http://static.ak.fbcdn.net/rsrc.php/z7O0P/hash/4hw14aet.png


What does rsrc.php really does? I know that rsrc stands for resource and rsrc.php/z[random]/hash or css/file.extenstion loads a file from somehwere.

Assuming /hash/ or /css/ is a folder which keeps the files like .xml .png .swf but whats with z[random] thing and why they want to load a file from a php? Is it for something like version control for the file or what? If so how to do it (in a simpler way)?

Answer

It's simple, these files are stored in a database. Anything after the SELF (script name, in this case the script is rsrc.php) is passed to the script as a param for the database. I use myself on image files, you base64 the image, store it in the database and usually with a bit of mod_rewrite magic your can get the url of the image to be youtsite.com/images/fish-with-wings when it is really doing this: yoursite.com/some-script.php/fish-with-wings which is really telling the database to look look for get the image from the database where title is = fish-with-wings, and it spits out the base64 for that file.

The advantages of having everything in the database are that for content writers its easier to reference a file and you can delete or purge, or even modify with some cool AJAX and it's also useful to stop hotlinking, which facebook hasn't done here but you could say, if the url is the the full path the redirect to a hotlink warning.

Comments