What is the length of a PHP session id string?

前端 未结 5 1159
天命终不由人
天命终不由人 2020-12-15 03:03

I\'m making a table in a MySQL database to save some session data, including session_id. What should be the length of the VARCHAR to store the

5条回答
  •  天命终不由人
    2020-12-15 03:33

    @sachleen answer isn't full.
    More detailed info about session id length is described here.

    Summary:

    128-bit digest (MD5)  
    4 bits/char: 32 char SID    
    5 bits/char: 26 char SID    
    6 bits/char: 22 char SID
    
    160-bit digest (SHA-1)
    4 bits/char: 40 char SID    
    5 bits/char: 32 char SID    
    6 bits/char: 27 char SID
    

    And sample regex to check session id:

    preg_match('/^[a-zA-Z0-9,-]{22,40}$/', $sessionId)
    

提交回复
热议问题