* Created: August 12, 2005 * Description: * Returns a GIF stream if a random playing card for the date given. * Randomness only works up to a specified date. Ie: all requests on * a specific day will return the same card. * Usage: * [your_file.html] * * * * * GET parameters: * card : Either 1 or 2. If this parameter is 1 then it returns the first card * otherwise it returns the second card. * * refresh : (optional) If present, it causes a refresh for a new random card. * overwriting the previous random cards for today's date. * ******************************************************************************/ define('INI_FILE', 'random_card.txt'); define('IMAGES_PATH','../images/cards/'); /** * Loads the cards from random_card.txt if any are present. * @returns associative array with keys: date, card1, and card2 */ function loadCards(){ return parse_ini_file(INI_FILE); } /** * Saves the cards to the ini file. */ function saveCards($card1, $card2){ $file = file(INI_FILE); for ( $i=0; $i"; } $cards = loadCards(); } else { $cards = array(); } if ( $cards['date'] && $cards['date'] == date('Y-m-d') && $cards['card1'] && $cards['card2'] ) { return $cards; } else { $cards = array( 'date' => date('Y-m-d'), 'card1' => randomCard(), 'card2' => randomCard() ); if ( $_GET['debug'] ){ echo "Saving cards to file...
"; } saveCards($cards['card1'], $cards['card2']); return $cards; } } // Handle the request if ( $_GET['card'] == '1' ){ $card = 'card1'; } else { $card = 'card2'; } if ( $_GET['refresh'] ){ $refresh = true; } else { $refresh = false; } $cards = getCards($refresh); if ( $_GET['debug'] ){ echo "Cards: "; print_r($cards); exit; } else { header('Content-type: image/gif'); $path = IMAGES_PATH.$cards[$card]; //echo ''; //exit; $fp = fopen($path, "r"); fpassthru($fp); fclose($fp); } ?>