Hello, I built a mobile version for my website. Does anyone know what is the PHP code that I nned to put in my INDEX file so if the visitor slide into my website with his phone he will automateclly redirct to mobile sub domain -> m.mysite.com ? Thank you in advance, Roi
What platform have you built the main site on? You'll have to check for the browser user agent (or screen res) & based on that send the user to the appropriate version of the site. If you're using a CMS like WordPress there are plenty of plugins out there that do that kind of thing, otherwise you'll be looking for a relatively complicated solution to do what you're looking for - For instance you'd need a bank of known user agents or screen sizes to check for & keep updated.
This a easy function what I use. $user_browser = $_SERVER["HTTP_USER_AGENT"]; function check_for_mobile($user_browser){ $mobile_browsers = array( // update this list if you need '2.0 MMP', // 'Mozilla', // 'Opera', // 'Opera', '240x320', 'AvantGo', 'BlackBerry', 'Blazer', 'Cellphone', 'Danger', 'DoCoMo', 'Elaine/3.0', //'EudoraWeb', 'hiptop', 'IEMobile', 'KYOCERA/WX310K', 'LG/U990', 'MIDP-2.0', 'MMEF20', 'MOT-V', 'NetFront', 'Newt', 'Nintendo Wii', 'Nitro', // Nintendo DS 'Opera Mini', 'Palm', 'Playstation Portable', 'portalmmm', 'Proxinet', 'ProxiNet', 'Small', 'Symbian OS', 'SymbianOS', 'TS21i-10', 'UP.Browser', 'UP.Link', 'Windows CE', //'WinWAP', 'Nokia', 'SHARP-TQ-GX10', 'Audiovox', 'Benq-Siemens', 'BlackBerry', 'Boost', 'Boost Mobile', 'Cingular', 'Eten glofish', 'Firefly Phone', 'Handspring', 'Hiptop2', 'Hitachi', 'Hp', 'HP', 'HTC', 'I-mate', 'Kyocera', 'LG', 'Mitsubishi', 'Mitsubishi Trium', 'Motorola', 'NEC', 'Nec', 'Palm', 'Panasonic', 'Pantech', 'Philips', 'Sagem', 'Samsung', 'Sanyo', 'SonyEricsson', 'Sharp', 'Sidekick', 'Siemens', 'Sprint', 'T-mobile', 'Toshiba', 'Treo', 'UTStarcom', 'Utstarcom', 'Verizon Wireless', 'VK' ); foreach ($mobile_browsers as $browser) { if (strstr($user_browser, $browser)) { return true; } } return false; } //USAGE: if(check_for_mobile($user_browser)){ ///looks like a mobile ... bla bla } else { /// not a mobile device.?! } PHP: OR You can make this requests $p1 = $_SERVER["HTTP_X_WAP_PROFILE"]; $p2 = $_SERVER["HTTP_PROFILE"]; $p3=$_SERVER["HTTP_x"]; PHP: one of this variable will return a adress like nds1.nds.nokia.com/uaprof/NE71-1r100.xml . But this work only if your visitor use default browser. If not (if they use Opera mini,UCWeb or other browsers) that HTTP headers will not return any info PS: Sorry for my english :-|
Thanks morency! I'm realy appreciate your help! Why do I need the last part in your code: $p1 = $_SERVER["HTTP_X_WAP_PROFILE"]; $p2 = $_SERVER["HTTP_PROFILE"]; $p3=$_SERVER["HTTP_x"]; PHP: is it instead $user_browser = $_SERVER["HTTP_USER_AGENT"]; ?
this was just a ideea. $p1 = $_SERVER["HTTP_X_WAP_PROFILE"]; $p2 = $_SERVER["HTTP_PROFILE"]; $p3=$_SERVER["HTTP_x"]; PHP: are just few varialbes from $_Server array . If any of this return a site address means that visitor is a "mobile" one.
and do I need to send p1, p2, p3 to function check_for_mobile? for example: if (check_for_mobile($p1)){ ?