Пример #1
1
function _hashed_id_parse_request($qv)
{
    $hashed_id = $qv->query_vars['hashed_id'];
    if (strlen($hashed_id) > 0) {
        $hashids = new hashids(AUTH_KEY, HASHED_IDS_MIN_LENGTH);
        $id = $hashids->decrypt($hashed_id);
        if (isset($id[0]) && is_numeric($id[0])) {
            $qv->query_vars['p'] = $id[0];
        } else {
            $qv->query_vars['pagename'] = $hashed_id;
        }
    }
    return $qv;
}
Пример #2
0
<?php

/* test for speed */
$number_of_ints_to_encrypt_at_once = 3;
$start_at = 0;
$end_at = 100;
/* this script will encrypt AND decrypt (when it decrypts it checks that hash is legit) */
require_once '../lib/hashids.php-5-3.php';
$hashids = new hashids();
function microtime_float()
{
    list($usec, $sec) = explode(' ', microtime());
    return (double) $usec + (double) $sec;
}
$total = 0;
$time_start = microtime_float();
for ($i = $start_at; $i <= $end_at; $i++, $total++) {
    $numbers = array_fill(0, $number_of_ints_to_encrypt_at_once, $i);
    $hash = call_user_func_array(array($hashids, 'encrypt'), $numbers);
    $numbers = $hashids->decrypt($hash);
    echo $hash . ' - ' . implode(', ', $numbers) . "\n";
}
$time_stop = microtime_float();
$total = number_format($total);
echo "\nTotal hashes created: {$total}.\nTotal time: " . ($time_stop - $time_start) . "\n";
exit;