PDA

View Full Version : How to determine screen res / width with PHP


tux
03-14-2009, 05:47 PM
Is it possible, I'm sure it must be, to determine a users screen resolution or browser width using PHP.

I want to check this before a page is displayed so as to avoid horizontal scroll bars if the user has a low res screen or to advise that the website is best viewed at a higher res.

Regards, Paul

davidj
03-14-2009, 07:14 PM
cant do this with php but you can with javascript

Found this example...
var winW = 630, winH = 460;

if (parseInt(navigator.appVersion)>3) {
if (navigator.appName=="Netscape") {
winW = window.innerWidth;
winH = window.innerHeight;
}
if (navigator.appName.indexOf("Microsoft")!=-1) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
}

document.write(
"Window width = "+winW+"<br>"
+"Window height = "+winH
)

remember you have to accomodate those that dont use javascript and the code has to fail gracefully