How to detect a mobile device with PHP?

Get user agent of user and redirect user to mobile version.