How To Redirect Mobile Users To Your Mobile Website

The PHP command


returns browser information, and we can get a list of all mobile browsers from this website.

Now if we only had a function we could use to know if the browser’s device is mentioned in $_SERVER[‘HTTP_USER_AGENT’], ah we do it’s

int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

This function finds the needle in the hay stack and returns the position in the string, which could start at zero. Let’s make a list of mobile OS’:


So then the script you need is:


if($android || $iphone || $bb || ipad >=0)
// redirect to mobile site
// show full site