How to detect browser resolution and version using php?

vibhavram

Junior Member
Mar 23, 2013
1
0
0
I am new to php and want to detect the browser version weather mobile or desktop and the pixel resolution so that I can build the output according to those settings.

Any help is thankful.
 

Graze

Senior member
Nov 27, 2012
468
1
0
Is Google broken or something?

You could find thousands of ways of doing this if you just googled it, like seriously.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Try google with "php detect browser" as the search.

However, that only picks apart the user-agent and for PHP's get_browser(), compares against a data file. It will tell you a some of what vibhavram asked for but not the current screen resolution or pixel density.

The only way to do that is with JavaScript code running on the client. PHP is running on the server.

So, any resolution logic has to be included in the response page sent to the client and run there. After it runs, it could pass the information on to the server to use in later pages by setting a cookie, or using POST/GET variables.

Google "javascript detect resolution screen"
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
Eek. I wouldn't build resolution specific pages server side.

You can either:
1) Use JavaScript to make the site adjust a bit based on the screen resolution. This can constantly adjust the page as the user resizes the window.
2) Use responsive CSS to define different CSS for various ranges of screen sizes.
 

purbeast0

No Lifer
Sep 13, 2001
53,487
6,331
126
Eek. I wouldn't build resolution specific pages server side.

You can either:
1) Use JavaScript to make the site adjust a bit based on the screen resolution. This can constantly adjust the page as the user resizes the window.
2) Use responsive CSS to define different CSS for various ranges of screen sizes.

i second this. the backend shouldn't know or care what browser the user is using.