How to determine if a user is on a PC or mobile phone
Because no matter what you do, sooner or later you will be wrong, each version of the site should contain a link to a page where the user can choose the appropriate format. Once they have selected, cookies are theirs, and if any, use that cookie as an override of what the user scent tells you.
In addition to user agent sniffing, if your site requires a login, you can keep this preference forever and reload it if necessary at login. If it's obvious from the user agent string, just use that, if it isn't, ask them to select from your list of available options and keep their default selection.
source to share
There is always a User Agent string. But that means keeping up with all the latest browsers, and differentiating between them isn't always easy.
Instead of being redirected to a completely different page, try using the media selector in your stylesheets to tweak normal content for a smaller screen.
source to share