1

I am storing $_SERVER['HTTP_USER_AGENT'] of a client in database. What is the recommended length that I could give to varchar(length) for HTTP_USER_AGENT?

this website shows value of HTTP_USER_AGENT. I visited from my PC, and the value is 109 characters long. From this I was planning to give varchar(150), but I want to confirm what can be the maximum value of HTTP_USER_AGENT. I don't want to give too long length to my varchar.

Mr.Web
  • 6,992
  • 8
  • 51
  • 86
Elyor
  • 5,396
  • 8
  • 48
  • 76
  • I don't know why you even mention varchar. You should have just left your question containing *"what can be the maximum value of HTTP_USER_AGENT"*. I don't see relevance here or why it would even matter. – Funk Forty Niner Aug 13 '15 at 12:00
  • 1
    this may help http://stackoverflow.com/questions/654921/how-big-can-a-user-agent-string-get – Dimag Kharab Aug 13 '15 at 12:01
  • I'd just use `TEXT` for it. The user agent is quite quirky in some browsers, and if you really want to ensure you're getting the whole thing, then don't limit it at all. – deceze Aug 13 '15 at 12:01
  • May be you can encrypt it and store – Dimag Kharab Aug 13 '15 at 12:02
  • @n01ze How does encryption help here?! – deceze Aug 13 '15 at 12:03
  • atleast it will reduce the size ... just saying , workaround – Dimag Kharab Aug 13 '15 at 12:03
  • @n01ze How does encryption reduce size?! – deceze Aug 13 '15 at 12:04
  • *"I'd just use `TEXT` for it."* @deceze which was an answer given http://stackoverflow.com/a/13506920/ in the duplicate I found the question to be. *Bad call on my part?* – Funk Forty Niner Aug 13 '15 at 12:04
  • 2
    @Fred-ii- Even if the answer happens to be extremely similar, the question was indeed very different as were the reasons for arriving at the answer. "I'm worried about the maximum row length and how to store long values in it" vs. "how much should I set aside for a particular type of value..." – deceze Aug 13 '15 at 12:08
  • You could use varchar(255) if you dont care about truncation. It depends why you are saving the data. Is it just for logging, or do you really need to store every byte? – Phil Aug 13 '15 at 12:09
  • @deceze Thanks for the added explanation. - and Elyor: Sorry about that, I made a mistake. After all, *I'm only human* ;-) – Funk Forty Niner Aug 13 '15 at 12:17

0 Answers0