How big can a user agent string get?

前端 未结 11 2160
清酒与你
清酒与你 2020-11-28 20:36

If you were going to store a user agent in a database, how large would you accomdate for?

I found this technet article which recommends keeping UA under 200. It does

11条回答
  •  半阙折子戏
    2020-11-28 21:12

    My take on this:

    • Use a dedicated table to store only UserAgents (normalize it)
    • In your related tables, store an Foreign Key value to point back to the UserAgent auto-increment primary key field
    • Store the actual UserAgent string in a TEXT field and care not about the length
    • Have another UNIQUE BINARY(32) (or 64, or 128 depending on your hash length) and hash the UserAgent

    Some UA strings can get obscenely long. This should spare you the worries. Also enforce a maximum length in your INSERTer to keep UA strings it under 4KB. Unless someone is emailing you in the user-agent, it should not go over that length.

提交回复
热议问题