Slip Posted October 8, 2008 Share Posted October 8, 2008 I want one url for a site that can be access by mobile devices as well as desktop pc's. So, my index page will have to contain some kind of script to detect what the user is browsing on and then redirecting to the appropriate directory. Problem is I cannot work out how to detect what the screen is of the user. I've tried Javascript to detect the screen.width and screen.height but when I tested the result in my Sony Ericsson mobile phone the output was 800 x 5000! So clearly this is not fool proof. Is there a way I can do this with PHP? I've read some odd posts referencing the USER_AGENT but it still seems a gray area. Link to comment https://forums.phpfreaks.com/topic/127557-mobile-device-detection/ Share on other sites More sharing options...
aximbigfan Posted October 8, 2008 Share Posted October 8, 2008 user agent would be the way to go. The user agent is a param in the header that tells the server what browser software the client has. In this case, you need to find out what the user agent of a PPC, then make a function to switch the content based on the user agent. Chris Link to comment https://forums.phpfreaks.com/topic/127557-mobile-device-detection/#findComment-659981 Share on other sites More sharing options...
aschk Posted October 8, 2008 Share Posted October 8, 2008 PHP cannot determine the size of the screen, however javascript may assist you in determining the viewable area. Link to comment https://forums.phpfreaks.com/topic/127557-mobile-device-detection/#findComment-659991 Share on other sites More sharing options...
Slip Posted October 8, 2008 Author Share Posted October 8, 2008 I've not had much experience with the USER_AGENT variable but I am guessing with each device that variable string will have the device manufacturer amongst it? If so, I guess I could loop through an array of manufacturers and once detected in the string then send the user to the mobile section. Does this make sense? $userAgents = array("nokia","SonyEricsson","HTC","LG"); for($i=0; $i<count($userAgents); $i++) { $chunk = explode($userAgents[$i], $_SERVER['HTTP_USER_AGENT']); if(count($chunk) > 1) { header("Location: mobile.html"); return; } } header("Location: standard.html"); Link to comment https://forums.phpfreaks.com/topic/127557-mobile-device-detection/#findComment-660000 Share on other sites More sharing options...
Slip Posted October 8, 2008 Author Share Posted October 8, 2008 Okay, I've just done a quick test and the following code looks good. Feel free to use this code as you please... $mobileAgents = array("AvantGo","Windows CE","Blazer","Palm","BlackBerry","SonyEricsson","Smartphone","MMP","Nokia","LG","NetFront","RIM","Xiino","WAP","Samsung"); $userAgent = $_SERVER['HTTP_USER_AGENT']; for($i=0; $i<count($mobileAgents); $i++) { $chunk = explode($mobileAgents[$i], $userAgent); if(count($chunk) > 1) { echo "This page is being viewed on a mobile device"; return; } } echo "Standard device page"; P.S. Can anyone tell me how to colour my code in the posts on this forum? Link to comment https://forums.phpfreaks.com/topic/127557-mobile-device-detection/#findComment-660011 Share on other sites More sharing options...
ifuschini Posted July 7, 2009 Share Posted July 7, 2009 I have published the last version of "Apache Mobile Filter", this open source project have, in the first six months, more than 600 downloads from sourceforge and I think the same from CPAN. The Apache Mobile Filter allows you to access WURFL from any programming language, not just Java and php that is traditionally used for dynamic mobile web sites. The module detects the mobile device and passes the WURFL capabilities on to the other web application as environment variables. It can also be used to resize images on the fly to adapt to the screen size of the mobile device. Try it and let me know your opinion. For more info: http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html Test Page: http://apachemobilefilter.nogoogle.it/php_test.php Link to comment https://forums.phpfreaks.com/topic/127557-mobile-device-detection/#findComment-870309 Share on other sites More sharing options...
xcoderx Posted July 7, 2009 Share Posted July 7, 2009 Pm me if u stil want to knw how to detect mobile device, wil gv u d best way to detect mobile device and pc. I had been working on mobile sites fa 4 years now. Am askin u pm coz atm am not on pc so il give it to u tomorrow Link to comment https://forums.phpfreaks.com/topic/127557-mobile-device-detection/#findComment-870466 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.