Search code examples
phpopensslphp-openssl

openssl_random_pseudo_bytes php function


output openssl_random_pseudo_bytes php function unreadable character.

I use this function to generate a unique string.

<?php
header('content-type:text/plain ; charset=utf-8');
$uniqid=openssl_random_pseudo_bytes(30 );
echo $uniqid ;
?>

output something like this :

#~�p�x�6�;g�ic�-z"���:i�

Solution

  • I must use bin2hex() function.

    <?php
    $uniqid=bin2hex(openssl_random_pseudo_bytes(30 ));
    echo $uniqid ;
    ?>
    

    also this function certainly does not product a uniqid .