Solved

get user info

Posted on 2004-08-08
6
256 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

864 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now