Page 1 of 1

Screen Resolution

Posted: Mon Aug 18, 2003 9:13 pm
by evilmonkey
Is it possible to have PHP (or possibly some other language) know a client's screen resolution?

A little background on my problem. I have a website that uses a bunch of picture which makes for a pretty darn nice backgound. The problem is, it only fits certain resolutions, otherwise a scrollbar appears (the one that moves left and right) and ruins the look of my whole site. So what I though I'd do is find out a user's resolution and judging by that, manupulate the picture sizes accordingly, something along the lines of:

Code: Select all

if ($resolution==1024*768){
echo "<img src="onepic.jpg">";}
else{
echo "<img src="anotherpic.jpg">";}
In reality, onepic, and anotherpic are the same picture but different size horizontaly. So please throw some ideas my way.

Thanks.

Posted: Mon Aug 18, 2003 9:23 pm
by BDKR
I would suggest Javascript. This is the kind of thing that it's made for.

Otherwise, if it's possible to get information regarding a users present resolution in the $_SERVER['HTTP_USERS_AGENT'] datum, then great!

Cheers,
BDKR

Posted: Mon Aug 18, 2003 9:42 pm
by evilmonkey
I don't think you can get information using the HTTP_USER_AGENT. I thik that only returns your browser information. Can someone be more specific on how I do this using JavaScript or PHP?

Thanks.

Posted: Mon Aug 18, 2003 10:37 pm
by BDKR
I didn't think you could get it from PHP, therefore it won't work with PHP.

That said, it's time to do some digging. Javascript will do it. Just dig into the DOM (document object model) or something and find which object holds the data you want. Perhaps the screen.width element would be of some help. If so, just write out the correct background using document.write to the body tag.

Google is your friend. :twisted:

Cheers,
BDKR

Posted: Mon Aug 18, 2003 11:08 pm
by Nay

Code: Select all

<script language="javascript">
<!--

var height = window.screen.availHeight;
var width = window.screen.availWidth;

if(width=="1024"&&height=="768") &#123;
document.change.src = "anotherimage.jpg";
&#125;

//-->
</script>

<img src="default.jpg" name="change" />
i hope that helped.........i wrote it quickly, so not sure if it works.......

-Nay

Posted: Tue Aug 19, 2003 4:38 am
by twigletmac
Check out the Client Side forum, there's a few threads about this. Basically it all comes down to passing the information from JS to PHP 'cause PHP doesn't know anything about the client's set-up.

Mac

Posted: Tue Aug 19, 2003 10:00 am
by evilmonkey
Yes, I know how to pass information from JavaScript (or anything else for that matter) to PHP. The easiest way to link it to a phpscript using:

Code: Select all

if(width=="1024"&&height=="768") &#123; 
window.location="thescript.php?width=1024&hieght=768"&#125;
Nay, that really helps. I will look into that. Chances are I will also have to cookie that information in order to remeber it on each page of my website. This is sure to get annoying :lol: . Thanks.