Site logo

Archived topic

Conditionally requiring php scripts

3 replies · Started by Han on September 9, 2018

Viewing posts 1–4 of 4

Hi there,

Is it possible to check the viewport width using PHP?

I created a few functions in separate files and would like to 'require' them inside the functions.php file based on certain viewport size.

Ed

Hi there,

you can't do it simply with pure PHP, as the script is run server side. There are some methods prescribed on stackoverflow on using Ajax or redirects to pass those variables. Might be worth checking out.

For pure PHP you can detect the UserAgent - so its device specific, heres a Stack on that:

https://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile-device

Hope it helps.

Hi David,

Thanks for the information!

I've decided to use http://mobiledetect.net/. Seems to be working fine.

Ed

Awesome :) Glad to be of help.

This archived topic is closed to new replies.