$history = $fcache->get('hash_history'); if (!$history) { $history = array(); } if (array_key_exists($chars, $history)) { return array_keys($history); } if (count($history) > $max) { $key_del = array_rand($history, 1); unset($history[$key_del]); } $history[$chars] = ''; $fcache->add('hash_history', $history); return array_keys($history); } // GET route $app->get('/', function () use($app) { $chars = 'DigHash'; $random = get_randoms(20); $history = do_history($chars); $app->render('hash.html', array('chars' => $chars, 'hash_rst' => cal_hash($chars), 'random' => $random, 'history' => $history)); }); $app->get('/:chars.html', function ($chars) use($app) { $random = get_randoms(20); $history = do_history($chars); $app->render('hash.html', array('chars' => $chars, 'hash_rst' => cal_hash($chars), 'random' => $random, 'history' => $history)); }); $app->notFound(function () use($app) { $app->redirect('/', 301); }); $app->run();
* * If you are using Composer, you can skip this step. */ require 'Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); $app->config(array('debug' => true, 'templates.path' => 'templates')); function cal_hash($chars) { $algos = hash_algos(); $hash_rst = array(); foreach ($algos as $algo) { $st = microtime(); $rst = hash($algo, $chars, false); $et = microtime(); list($ss, $si) = explode(' ', $st); list($es, $ei) = explode(' ', $et); $hash_rst[str_replace(",", "_", $algo)] = array('rst' => $rst, 'time' => $ei + $es - $si - $ss); } return $hash_rst; } // GET route $app->get('/', function () use($app) { $chars = 'HASH'; $app->render('hash.html', array('chars' => $chars, 'hash_rst' => cal_hash($chars))); }); // POST route $app->get('/:chars.html', function ($chars) use($app) { $app->render('hash.html', array('chars' => $chars, 'hash_rst' => cal_hash($chars))); }); $app->run();