you can’t do it simply with pure PHP, as the script is run server side. There are some methods prescribed on stackoverflow on using Ajax or redirects to pass those variables. Might be worth checking out.
For pure PHP you can detect the UserAgent – so its device specific, heres a Stack on that: