What is a RELIABLE way to detect a client’s browser and its version number?

What is a reliable way to detect someone’s browser and its version number? From what I’ve seen, things like the navigator object in JavaScript simply do not work toward this end, and neither do a lot of these really hacked-together solutions I’m coming across. There are one or two currently functional JavaScript code snippets I’ve come across that’ll tell me whether someone is using Firefox, Chrome, etc., but they don’t describe the version number of each browser. How can this be found, and how can it be done reliably? (The front-ends are a couple of Flex applications.)