Solved

get user info

Posted on 2004-08-08
6
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

628 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