Solved

get user info

Posted on 2004-08-08
6
272 Views
Last Modified: 2008-01-09
I am looking for a way to somehow get information about the visiting use through PHP (not Javascript).  I am looking for a way to get resolution and color depth.  I am pretty sure that there is a way to get this information through PHP, but I can't seem to find it on the net.  Also, if possible the screen width and height would be nice as well as javascript version.  Chances are that the last 3 wont be able to be acheived, but I am not sure.

Thanks!
Matt
0
Comment
Question by:mattjp88
  • 3
  • 2
6 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 63 total points
ID: 11747961
Hi

I'm not experienced enough in PHP to tell you how to do that. The only things I know are how to get the user's IP:
$_SERVER['REMOTE_ADDR'];

and the host of the address:

gethostbyaddr($_SERVER['REMOTE_ADDR']);


However, I can tell you how to do these things in Javascript. (screen resolution is just screen width by screen height)
[I know you mainly want it in PHP, but this is just for reference for Javascript just in case]

====================================================
function getIP() {
   //This requires the user to have Java enabled. Use $_SERVER['REMOTE_ADDR'] instead.
   if (!document.all && navigator.javaEnabled()) {
      return(java.net.InetAddress.getLocalHost().getHostAddress());
   }
   return false;
}

function getScreenWidth() {
   if (window.screen) {
      return(window.screen.width);
   }
   return(getScreenWidthJava());
}

function getScreenWidthJava() {
   if (navigator.appName=="Netscape" && navigator.javaEnabled()) {
      return(java.awt.Toolkit.getDefaultToolkit().getScreenSize().width);
   }
   return false;
}

function getScreenHeight() {
   if (window.screen) {
      return(window.screen.height);
   }
   return(getScreenHeightJava());
}

function getScreenHeightJava() {
   if (navigator.appName=="Netscape" && navigator.javaEnabled()) {
      return(java.awt.Toolkit.getDefaultToolkit().getScreenSize().height);
   }
   return false;
}

function isJavaEnabled() {
   if (navigator.javaEnabled()) {return true;}
   return false;
}

function getBrowserName() {
   return(navigator.appName);
}

function getPlatform() {
   return(navigator.platform);
}

function getBrowserCodeName() {
   return(navigator.appCodeName);
}

function getMaxScreenWidth() {
   if (window.screen) {
      return(window.screen.availWidth);
   }
   return false;
}

function getMaxScreenHeight() {
   if (window.screen) {
      return(window.screen.availHeight);
   }
   return false;
}

function antiAliasingFonts() {
   return(window.screen.fontSmoothingEnabled);
}

function getBrowserVersion() {
   return(navigator.appVersion);
}

function getColorDepth() {
   if (window.screen) {
      return(window.screen.colorDepth);
   }
   return false;
}

function getNumberOfColors() {
   if (window.screen) {
      return(Math.pow(2,window.screen.colorDepth));
   }
   return false;
}

function hasCSS() {
   var bool = (document.all) ? checkcss : document.checkcss;
   return(bool);
}

function getLanguage() {
   var bool = (document.all) ? navigator.browserLanguage : navigator.language;
   return(bool);
}

function getReferrer() {
  return(document.referrer);
}

function getHistoryLen() {
  return(history.length);
}


Regards,
Zyloch
0
 
LVL 25

Assisted Solution

by:Marcus Bointon
Marcus Bointon earned 62 total points
ID: 11747970
You can't get this directly through PHP because at the time the script runs, it's on the server, not the client. You will have to get this data using Javascript, which you can then report back to a PHP script. This is an example as used by the summary web log analyser:

http://summary.net/manual/javascript.html

In this case it's relying on making static requests that can be later analysed in the logs, but you'll just need to get it to call a PHP script with the parameters instead, at which point you can do what you like with them, so change this line:

ls="/log____image.gif?...

to

ls="/userparams.php?...
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11747987
Hmm.. had a look at that. If that's the case, this function:

function getColorDepth() {
   if (window.screen.colorDepth) {
      return(window.screen.colorDepth);
   } else if (window.screen.pixelDepth) {
      return(window.screen.pixelDepth);
   }
   return false;
}
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11748054
The Javascript summary provides is pretty old and clunky, so I wouldn't follow it too much - it's lacking some basic things like type attributes, and its installation instructions break W3C validation, however, it will do the trick. Your function collection is far neater, it just needs a higher-level function to gather all that info and turn it into a request, so the answer is somewhere between the two. Fancy writing it?
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11748933
True, I'll have to wait and see how he wants it though, (and I'm prolonging it ;)
0
 
LVL 6

Author Comment

by:mattjp88
ID: 11825982
Well, I wanted a way for me to get some of the user datails only through PHP, not javascript.  And from what you said and also what many internet sites say; it's impossible.  Thanks for your help!

-Matt
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question