I need some help in how to do the following redirect to a mobile phone in php. I'm using a js redirect but I need something more sophisticated. I've searched and found several php scripts that haven't worked for me possibly because I'm a php noobie. Here is what I would like:

- detects "most" mobile small screen devices including iphone, Android .....
- redirects from the main site to a mobile site
- code for a link-back to the main site from the mobile site that will prevent a do loop that tries to link back to the mobile site.

A final question I have is: must the main and mobile site pages both be php? Can I just rename the page's extension to dot php to make a php script run properly on them?

Your help will be appreciated.