I was looking through the code for Zend_Session to try and get a better understanding of how to implement session starting. Within the code, they do something that I don't quite understand.
$hashBitsPerChar = ini_get('session.hash_bits_per_character');
if (!$hashBitsPerChar) {
$hashBitsPerChar = 5;
}
switch($hashBitsPerChar) {
case 4: $pattern = '^[0-9a-f]*$'; break;
case 5: $pattern = '^[0-9a-v]*$'; break;
case 6: $pattern = '^[0-9a-zA-Z-,]*$'; break;
}
if(!preg_match('#'.$pattern.'#', $id)){
session_id(md5(session_id()));
$regenerateId = true;
}
What I'm having difficulty understanding is why they have a pattern that has a not ( ^ ) and then if it does not match they create a temporary session id before starting the session. This to me doesn't make sense - why do they do a pregmatch against not having 0-9a-zA-Z-,
? I just don't quite understand whats going on here and would like to understand.
Thanks