Hello, i want to redirect peaple who goes in my site to other page if they are using a mobile browser with a php o java script. Thanks
+1
A:
You need to check the User-Agent
header:
if (preg_match("/(BlackBerry|(iP(hone|od))/i", $_SERVER['HTTP_USER_AGENT'])) ) {
...
}
SLaks
2010-04-18 16:23:16
there is an error on the code i cant detect, can you please check it?
DomingoSL
2010-04-18 17:04:47
A:
The $_SERVER['HTTP_USER_AGENT'] contains word "BlackBerry" or "iPhone" respectively. "iPod" too if it's iPod Touch.
Timo
2010-04-18 16:24:36
A:
Very easy will be to parse USER-AGENT string or get_browser() PHP function. Try :
echo $_SERVER['HTTP_USER_AGENT'];
var_dump(get_browser(null, true));
Every browser is sending own HTTP_USER_AGENT string.
Mobile devices USER_AGENT list
For completed solution take a look to bavotasan page or just google.
retro
2010-04-18 16:29:39
+1
A:
In addition to checking the User-Agent
header, you may also want to check the X-Wap-Profile
and Profile
headers, since some third-party browsers may not send a correct User-Agent
header (they may be spoofing an IE or Firefox header). The order that I like to check the headers, when looking for mobile clients, is:
- X-Wap-Profile
- Profile
- User-Agent
Marc Novakowski
2010-04-18 17:07:21