Sunday, November 8, 2009

Flash caching PHP response

Recently I ran into an issue where I would call a PHP file that would generate a unique id and return that to Flash (I am sure I could do the same thing from within flash but decided to just use PHP's uniqid to solve this for now) The id that comes back is used for files the user is uploading. The problem I noticed is that Flash would make the call to the PHP file and then get back the same UUID everytime. I thought that perhaps Flash was caching the page and then just loading it instead of re-requesting it from the web server. In summary this was somewhat true. The page was being cached somewhere and needed some PHP header references to prevent from caching properly.

Flash kept loading the same values from a PHP script that should have been generating different values on every call.

I included these header functions and parameters at the top of my PHP file.
header( "Pragma: no-cache" );

header( "Cache-Control: no-cache" );

header( "Expires: Sat, 01 Jan 2000 00:00:00 GMT" );

 Happy programming.

No comments: