3

I've got a page that will be loading a bunch of fairly high resolution images, as well as a full HD video. Is there a way to detect if someone is using cellular on their phone vs wifi, so I can use a lower resolution version of the image, and the video?

Preferably I would like to do this in PHP, but if I can't using JavaScript is also an option.

I thought about using the User Agent string but this would only tell me if its a mobile device, not if its on wifi or cellular. I've seen several suggestions saying to use IP databases but they all seem to cost money, and it's simply out of the question to pay for the database based on current financials.

  • I do not know what databases you are talking about, however, there are black list operators that will indicate a telecom subscriber or even cellular IP address allocation. Search for one of those and do a fast and dirty RBL look-up against one of them to test your idea. Other than that, I am not sure what to tell you. The browser screen size should be apparent enough and the @Media media query should work just fine. w3schools.com/cssref/css3_pr_mediaquery.asp You will have to learn how to use CSS for this if you are not fully familiar. Cheers!! – closetnoc Jul 21 '16 at 0:17
1

You have the following general choices:

  1. Examine the speed of the connection. You would have to devise some sort of bandwidth test that would attempt to tell whether you have a fast or slow connection. It sounds like this is what you really care about - there is no shortcut other than attempting to measure said speed.

  2. Examine characteristics of the device. Using a number of heuristics such as size of screen, browser user agent, touch availability, etc..., you can estimate whether it's likely this is a cellular device. That of course does not tell you what kind of connection the device is on.

  3. Examine where the connection comes from. Here you examine the origin of the client's IP address and attempt to identify it as coming from a cellular provider. This will involve building or acquiring some sort of knowledge base about IP ranges or reverse lookup domain names so you can correlate a particular IP address with a mobile provider.

  4. You can allow the user to specify whether they want an SD or HD version of your site. Obviously, this is not automatic and therefore is not as desirable as an automatic option if you can get one to work, but is a possible fallback.

  • Actually my concern is two fold, yes connection speed, but also for users of limited data plans. So basically the only sure fire way is the IP method? – lightbord Jul 21 '16 at 0:26
  • @lightbord - Well, you can't detect that. Maybe option 4 is best. – jfriend00 Jul 21 '16 at 0:27
  • I know I can't detect the size of the data plan but the ip method will allow me to determine if it's coming over cellular or wifi? – lightbord Jul 21 '16 at 0:29
  • @lightbord - Theoretically, the IP canl identify the source as cellular provider or not, but you will have to figure out if you can get the right IP address data to be able to accurately act on that. – jfriend00 Jul 21 '16 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.