Load php file according to screen resolution

Asked

Viewed 212 times

0

Hello,

I know there are frameworks like bootstrap (which I use) but I really want to make a separate template for mobile devices.

My doubt is how to call the php file according to screen resolution?

  • PHP has no way of knowing the screen resolution, it runs on the server. You could only do that if something in the customer carried something via AJAX giving this information. Now, one observation: I can’t say this, but you’re probably trying to solve a problem with the wrong tool. If you want different applications according to the resolution, redirect the person with JS. Which could be a problem, because I might have the desktop browser window scaled into a piece of the screen, and then I’ll get the mobile app. You need to see if that’s the intention.

  • Thanks @Bacco a little while ago I found the answer I needed in this post in this post2 has explanation about the user agent, with this I found the solution in class mobile_detect on github and has a cool explanatory video on youtube

  • The user-agent is different from what you asked. And that’s what these posts I know, and it doesn’t work right. In some very specific cases, the script may be right, but if you adopt such a solution, you will always have problems with devices that do not provide the expected string. It may be that you test on 2 or 3 very common devices and everything works, but in a real case, only the user take a different browser (or even an update of the standard OS browser), can already change everything.

  • I understand that the user agent is related to the browser, but I believe that from this it was possible to structure the class, it is just an assumption of my own. But because the class does not work, seems to have good recommendations? In this file test apparently works

  • "Apparently" is the key word. It will certainly work in many cases, which is why the staff adopts these solutions. The question is, what if it doesn’t work? How do you diagnose it? It all depends on your target audience. If you make a website for a trendy Boy Band, it’s nice to have modern devices, and a portion that has problems doesn’t affect you. If you’re going to make a website for a lab, where people of every type and income range take medical exams, then you have to prioritize access from an iPad to a Chinese tablet. "Right and wrong" depends on the context.

  • Truth is a risk the class does not keep track of new updates and does not load properly

  • But I was thinking of having some 3 resolutions, "standard" cell phone, "standard" tablet and computer, already good to start and meet a considerable portion.

  • A good stick break can be you have in the menu the option of the person change the view if you want. In this case, the user does not get stuck in the wrong model, in case there is any problem in the detection.

  • Thanks for the suggestions @Bacco

  • It is an innocent question that seems simple but is actually very broad because there are different ways to solve. It depends on N factors.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.