Screen Resolution

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Screen Resolution

Post 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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post 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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post 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.
Post Reply