(PHP) How to detect that user's computer/brows

2020-04-14 09:11发布

问题:

Lately I am updating my software to support dark mode, in response to research that looking at a paper-white background display is bad for the eyes and for sleep rhythms. Is there a way to detect from PHP that a user's browser and/or OS are set to Dark Mode? How about detecting that it is set to nighttime mode (reduction of blue colors)?

回答1:

Since PHP executes on the server without any knowledge of the client, there is no direct way of finding this out.

If it is possible to detect the color mode in JS, you could embed a small JS script to your site, that sets a cookie. Cookies are transmitted to the server on request, so PHP is able to query them.