Jump to content

Recognizing mobile browsers


sc00tz

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/174281-recognizing-mobile-browsers/
Share on other sites

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.