NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - random_bytes

Trieda

Koreň \ Bez triedy

Metóda - random_bytes

(PHP 7)

random_bytes() is used to generate a pseudo-random string of bytes, that can be surely used for cryptographic operations.

As a source of entropy is used "getrandom(2)":https://manpages.debian.org/…om.2.en.html (on Linux systems) or "CryptGetRandom":https://msdn.microsoft.com/…=vs.85).aspx (on Windows systems). On other systems (or if none of the previous is available), /dev/urandom is used.

If none of the above sources can be used, an exception is thrown.

Procedurálne

Parametre

NázovDátový typPredvolená hodnotaPopis
$lengthint

The length of the requested string in bytes.

Mávratovej hodnoty

Vracia: string

Returns a string of the requested length containing pseudo-randomly generated bytes.

Príklady

Generating a pseudo-random token (encoded to base64):

<?php
    $randomBytes = random_bytes(64);
    $token = base64_encode($randomBytes);
    echo $token;
?>

Súvisiace manuály

      Aktivity