Last place I worked, we used WURFL for a while. It's the best of the free solutions. (We hosted it via JSP, but I believe it can be hosted on PHP.) We finally abandoned it in favor of a paid solution ($5,000 per year), but it was running a close second to the paid solution.
But as Philip said, there isn't any really good JS-based solution. You'd be amazed at how many mobile devices just don't properly support JS, for starters. If you don't care about such low-end devices, maybe you can get away with JS, but you're abandoning a pretty good sized chunk of the market by doing so.
And if the idiots you are doing this for can't understand that, well...there are other people out there you can work for who will be more likely stay in business. <grin style="sickly"/>
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.