I am using randomly generated numbers as session variables to identify the sessions in a PHP application. To make further security proof what ways should I follow?
Asked
Active
Viewed 2,561 times
1
Gilles 'SO- stop being evil'
- 51,955
- 14
- 122
- 182
Jayanta Kumar Nath
- 19
- 1
- 3
1 Answers
3
The best way to generate random tokens for security purposes in PHP is using openssl_random_pseudo_bytes() to obtain some random bytes, and then bin2hex to make them printable.
$token = bin2hex(openssl_random_pseudo_bytes(16));
You can safely use $token for your session identifier, CSRF tokens, etc.
OtherDevOpsGene
- 1,475
- 12
- 12
Adi
- 44,095
- 16
- 138
- 170
/dev/urandom(a better source of randomness thanmt_rand()). – perror Nov 12 '13 at 09:39