Is there a PHP analogue of @media-queries?

I need depending on the width of the screen to show the different codes generated in PHP.
As this the right approach? Is there a PHP analogue of @media-queries?
July 2nd 19 at 17:31
3 answers
July 2nd 19 at 17:33
Solution
Hello, Sergey!

PHP can't get the width of the browser window, because it runs on the server not on the client. But JS can. In such cases, usually, pass parameters to the server via AJAX. Here's an example: should look Like the PHP code to query the resolution of the client browser?

Maybe You'd better edit the required code is not in PHP but in JS ?
OK, I didn't even think about Ajax, it will be convenient) - caleb_Stehr commented on July 2nd 19 at 17:36
: you can try without AJAX, and to generate JS code directly in PHP. However, I think it's not very good practice - Garland36 commented on July 2nd 19 at 17:39
: pastebin.com/XkzzWNCR - Garland36 commented on July 2nd 19 at 17:42
: I have a provider banned Pastebin))) - caleb_Stehr commented on July 2nd 19 at 17:45
: www.linux.org.ru/forum/talks/11199026 - caleb_Stehr commented on July 2nd 19 at 17:48
bad provider) There was a code of the links, which is the answer) - Garland36 commented on July 2nd 19 at 17:51
: there is a good add-on for browsers called a frigate), the Most simple solution to open a websites through a proxy bourgeois - Garland36 commented on July 2nd 19 at 17:54
: Yes, I have remembered that I have my own proexe on Veske, looked at all) Now implement left) - caleb_Stehr commented on July 2nd 19 at 17:57
July 2nd 19 at 17:35
Solution
No, php is server side, it knows nothing about the width and height of your device. The only thing that comes to mind is Ajax. In General, if described in detail the meaning of the task may be able to find a better solution
Yes, Ajax will be the most convenient) - caleb_Stehr commented on July 2nd 19 at 17:38
July 2nd 19 at 17:37
Solution
No, of course. Well it is possible in PHP to generate the JavaScript that will ask the page, its size, and send info to server using Ajax. But:

1) it is a perversion
2) when you first load the page, you'll get nothing
3) better stop to render content through PHP, but to write directly to JS, Ajax which will load the desired response from the server
For 3 way and go. - caleb_Stehr commented on July 2nd 19 at 17:40

Find more questions by tags PHP