Casual Games, Social Software

Read more at the weblog »

Secure Media

The original SecureMedia.php is a class to prevent other websites from linking directly to your games by using an encrypted key and password combined with a PHP script that keeps your flash games secure, so that they can only be accessed via your website.

The PHP code pretends to be a .swf or .dcr file by sending out the correct Content-Type headers and, if the games is not being hotlinked to, the raw data also.

This new version of SecureMedia.php handles the creation and sending of ETag and Last-Modified headers, enabling browsers who request multiple copies of the same game to use their own cache, therefore saving the web server a great deal of bandwidth.

A web server running PHP and the ability to create or edit .htaccess files.

See the README with Florian's original code for setup and installation. Backup and replace SecureMedia.php with this copy to enable the ETag and Last-Modified headers.

Use this piece of code in your .htaccess so that flash cookies don't get confused by the URL changing constantly. This works by putting the key into the query string of the embed/src tags, tricking flash into thinking that the URL hasn't really changed.

  RewriteEngine on
  RewriteCond %{QUERY_STRING} ^SM([a-fA-F0-9]{32})\.(swf|dcr)$ [NC]
  RewriteRule ^path/to/game/(.*)$ /path/to/securemedia.php?file=$1&key=%1

SecureMedia can be downloaded from here:
Download Secure Media or view the source

Suttree Beatniks with better clothing, brought to you by Duncan Gough. About Archives Casual Game Dev Code Disclaimer EcoLocal Music Knows PMOG Tumblee
Links for Saturday, October 11th, 2008