I am using this one:
$isMobile = (bool)preg_match('#(ip(hone|od)|android.+mobile|opera m(ob|in)i|windows (phone|ce)|blackberry'.
'|s(ymbian|eries60|amsung)|p(alm|rofile/midp|laystation portable)|nokia|fennec|htc[-_]'.
'|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})#i', $_SERVER['HTTP_USER_AGENT'] );
It's short and does detect most mobile users (or rather smartphones). iPad and Android-Tablets won't be classified as 'mobile' since they have bigger screen sizes.
If you want to catch Tablets as well, you can use this:
$isMobile = (bool)preg_match('#(ip(hone|od|ad)|android|opera m(ob|in)i|windows (phone|ce)|blackberry|tablet'.
'|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp|laystation portable)|nokia|fennec|htc[-_]'.
'|mobile|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})#i', $_SERVER['HTTP_USER_AGENT'] );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…