Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can i determine a visitors screen resolution? 2

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Does anyone know if it possible to determine a users screen resolution when they click on my site..i want to keep a record of this info in a file..i know it is possible using vb eg..

<SCRIPT LANGUAGE=VBScript>
<!--
ScreenHeight=window.screen.height
ScreenWidth=window.screen.width

-->
</SCRIPT>

how can i do this same thing in php and return the results to a varible? Can i?
 
Sorry, but you cannot do this in PHP.

You can do it in Javascript though (same syntax as vbscript though).

:(

Chad. ICQ: 54380631
 
Well, you can't really do it in JavaScript, well at least for both browsers.

In IE, you can get the size of the browsing window, but then you don't take into account the size of the borders and top.

In Netscape, there are functions that take that into consideration.

So, its not possible with PHP, like inlandpac said, but you can pseudo do it with JavaScript.

You might want to check out the JavaScript forum.

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
I must disagree witht he assessment about 'can't really do it in javascript'.

If I do the following

<script language=&quot;javascript&quot;>

ScreenWidth = screen.width;
ScreenHeight = screen.height;

alert(ScreenWidth + &quot; x &quot; + ScreenHeight);

</script>

I get the same results in IE (to 5.5), NS => 4, and even NS6

On one of my systems I get 800 x 600 and on another I get 1024 x 768.

Chad. ICQ: 54380631
 
I stand corrected. I knew there were functions like window.outerHeight and window.outerWidth that worked in NS, but I was not aware of the screen.width and screen.height functions.

Hmm, I learned something new today as well.

Thanks,
-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Thanks for your help..
i dont know much file i/o using Jscript but What if i wrote those jscript variables to a text file on the server. I could then access this info using php.. I suppose this would give me the info on the previous visitor..that would do. Would it be possible to do it this way?
 
You can create a cookie with javascript and then access that information via PHP. The only problem is that when a cookie is set, it cannot be retrieved within the same page instance (meaning, you cannot view the cookie unless you hit 'refresh'). In any case, this is still a viable way to get the user's resolution, store it in a cookie, and retrieve it via PHP.

Code:
<html>
<head>
<title>Set a cookie</title>
<script language=&quot;JavaScript&quot;>
<!--
expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+12)

if (document.cookie != &quot;&quot;) {
var screenRes = document.cookie.split(&quot;=&quot;)[1]
   screenRes = screenRes.split(&quot;,&quot;)
   screenWidth = screenRes[0]
   screenHeight = screenRes[1]
}
else {
   screenWidth = screen.width
   screenHeight = screen.height
}

function setcookie() {
     screenRes = new Array(screen.width,screen.height);
     document.cookie = &quot;screenRes=&quot;+screenRes+&quot;;expires=&quot; + expireDate.toGMTString()
}

function deletecookie(){
     if (document.cookie != &quot;&quot;) {
          thisCookie = document.cookie.split(&quot;; &quot;)
           expireDate = new Date
           expireDate.setDate(expireDate.getDate()-1)
           for (i=0; i<thisCookie.length; i++) {
                cookieName = thisCookie[i].split(&quot;=&quot;)[1]
                document.cookie = &quot;screenRes=&quot;+screenRes + &quot;;expires=&quot; + expireDate.toGMTString()
           }
     }
}
//-->
</script>
</head>
<body onLoad=&quot;setcookie();&quot;>
<?php
echo $screenRes;
?>
</body>
</html>

Have fun!
Chad. ICQ: 54380631
 
ok thanks heaps ill give it a go...ill let you know how i get on
dave
 
Just a quick note.

screen.availheight

will take into account the size of the users maximum viable size (eg, subtract size of taskbar from total vertical resolution of 864 and i get 836 from .availheight

HTH Scott Cybak
scott@athree.com
 
Yes this is definitely an option depending on what you are trying to accomplish.

Please be careful with regard to case. Netscape does not recognize screen.availheight but it does recognize screen.availHeight.

Netscape can be a bugger!

Chad. ICQ: 54380631
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top