<?php
if (!defined('PHP_EOL')) {
define('PHP_EOL', "\r\n");
}
// generate the 32bit byte array (if you have the "openssl_random_pseudo_bytes" function available)
if (function_exists('openssl_random_pseudo_bytes')) {
$random_key = openssl_random_pseudo_bytes(32);
} else {
// this is the longer way to do it...
$random_key = '';
for( $i = 0; $i < 64; $i++) {
$random_key .= ((bool)rand(0, 1) ? chr(rand(65, 90)) : rand(0, 9));
}
$random_key = hex2dec($random_key);
}
// this is it as hex
print "Hex key: " . bin2hex($random_key) . PHP_EOL;
print PHP_EOL;
// this is the base64 string that you want to save
print "Save this string: " . base64_encode($random_key) . PHP_EOL;
Fatal error: Uncaught Error: Call to undefined function hex2dec() in /in/rZOTf:16
Stack trace:
#0 {main}
thrown in /in/rZOTf on line 16
Process exited with code 255.