sc00tz Posted September 15, 2009 Share Posted September 15, 2009 I have a site set up that users can sign into and then submit a form to a database. I want users to be able to access the logged-in site from a mobile browser or regular browser, but I need to put some code into the PHP form such that their submission is rejected if they did NOT submit it using a mobile browser (iPhone, Blackberry, Pre, whatever). Suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/174281-recognizing-mobile-browsers/ Share on other sites More sharing options...
backie Posted September 15, 2009 Share Posted September 15, 2009 Basically all you need to do is check $_SERVER["HTTP_USER_AGENT"] for browsers that are used on mobile devices. Last time I seen a is_mobile() function it had about 30+ different browsers so have fun compiling the list. Quote Link to comment https://forums.phpfreaks.com/topic/174281-recognizing-mobile-browsers/#findComment-918711 Share on other sites More sharing options...
Psycho Posted September 15, 2009 Share Posted September 15, 2009 I want users to be able to access the logged-in site from a mobile browser or regular browser, but I need to put some code into the PHP form such that their submission is rejected if they did NOT submit it using a mobile browser When you say you want users to be able to access with a "regular browser", but you then want to reject their submission, that makes no sense to me. Anyway, you might be able to utilize the CSS "@media" rule to make it such that the form is only displayed for mobile browsers int he first place since there is a type of "handheld" that is recognized. Basically the CSS can specify different style sheet properties based on the media type of the output. So, for a "handheld" type you would set the display property of the form to be displayed, if not a handheld then make the display none. Quote Link to comment https://forums.phpfreaks.com/topic/174281-recognizing-mobile-browsers/#findComment-918743 Share on other sites More sharing options...
grissom Posted September 15, 2009 Share Posted September 15, 2009 One way I once tried back in the past was to write a bit of javascript to put the screen width into a hidden field in the form. When the form gets submitted, use PHP to see what the screen width is. If its less than 800 pixels, then its probably a mobile device. However, now many mobile devices have bigger screen resolutions, that's probably not as effective as it once was. Quote Link to comment https://forums.phpfreaks.com/topic/174281-recognizing-mobile-browsers/#findComment-918776 Share on other sites More sharing options...
Bricktop Posted September 15, 2009 Share Posted September 15, 2009 Hi sc00tz, A quick Google came across this website http://detectmobilebrowsers.mobi/ It has a function generator which will allow you to choose how you want to treat each individual mobile device, and also has a redirect option if people are using a regular browser. I agree with mjdamato in that it's pointless showing the form to users using regular browsers if they are unable to submit. I would suggest using the above and redirecting them to a custom page which shows a message along the lines of "You must be using amobile device to view this page" Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/174281-recognizing-mobile-browsers/#findComment-918782 Share on other sites More sharing options...
sc00tz Posted September 16, 2009 Author Share Posted September 16, 2009 Yeah I suppose I didn't phrase it well. I still have to decide if I want to redirect regular non-mobile browsers or just log it if one is used when filling out the form. Thanks a lot for the advice, I'll check out the site. Quote Link to comment https://forums.phpfreaks.com/topic/174281-recognizing-mobile-browsers/#findComment-919688 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.