PHP: creare un token identificativo univoco per gli utenti

In PHP è semplice creare un token identificativo per ciascun utente.

La soluzione è la seguente:


function uniq_user_token() {
    $id = uniqid();
    $str = password_hash($id, PASSWORD_DEFAULT);
    return strtolower(preg_replace('/[^a-z0-9]+/i', '', $str));
}

Torna su