...

View Full Version : Display User's Ip Address, Browser Type, Browser Resolution, etc..



JaymeNYC
02-16-2010, 04:50 PM
I would like to develop a simple 1 page site where it will display the users IP Address, Browser Type, Browser Resolution, and whether Javascript is enabled or disabled..

I have this for the first 2



<?php
$ip = getenv('REMOTE_ADDR');
echo "<p>IP: $ip</p>";
?>

<?php
$browser = getenv('HTTP_USER_AGENT');
echo "<p>Browser Type: $browser</p>";
?>


its pretty simple 4 right now just tryin to get everythin to work.. is there any other type of useful information i can add?

JAY6390
02-16-2010, 05:09 PM
It might be worth looking at
http://php.net/manual/en/function.get-browser.php
to see what other browser info you can use (such as version number and so on)

Fou-Lu
02-16-2010, 05:12 PM
Resolution and javascript detection cannot be done with just php. PHP does not care one bit about the browser itself, just what the browser tells it about itself. Using browscap you could actually find out if JS is supported by the browser, but not if its actually enabled.

As for useful information, the ip and user agent have limited use. Since these are provided to PHP by the client, there is no guarentee on its validity.

JaymeNYC
02-16-2010, 05:15 PM
It might be worth looking at
http://php.net/manual/en/function.get-browser.php
to see what other browser info you can use (such as version number and so on)

thx! I see it shows Javascript = 1 and im guessing if theres no javascript it would be Javascript = 0.. I'm not to good with php but how would I change the value from 1 to Yes and 0 to No?

Fou-Lu
02-16-2010, 05:20 PM
thx! I see it shows Javascript = 1 and im guessing if theres no javascript it would be Javascript = 0.. I'm not to good with php but how would I change the value from 1 to Yes and 0 to No?

No, that only indicates if JS is supported. Disable you're JS, it should still indicate a 1.
To change it to yes and no:


function convertBoolToYesNo(&$val, $key)
{
if (is_bool($val))
{
$val = !$val ? 'No' : 'Yes';
}
}

$aItems = get_browser();
array_walk($aItems, 'convertBoolToYesNo');

Something like that.


Change the algorithm, I believe get_browser returns several string values as well.

JaymeNYC
02-16-2010, 05:24 PM
No, that only indicates if JS is supported. Disable you're JS, it should still indicate a 1.
To change it to yes and no:


function convertBoolToYesNo(&$val, $key)
{
if (is_bool($val))
{
$val = !$val ? 'No' : 'Yes';
}
}

$aItems = get_browser();
array_walk($aItems, 'convertBoolToYesNo');

Something like that.


Change the algorithm, I believe get_browser returns several string values as well.


some of those examples didnt work 2 well.. since the Javascript wont let me know if its actually enabled how do I check that? im going to be using this site for users so i can easily find out what browser they r usin and if javascript is enabled

Fou-Lu
02-16-2010, 05:36 PM
The only way to check if JS is enabled is to use js to set a cookie and let php retrieve it. Otherwise, you cannot detect this. My first post in this thread indicated that browser specific configurations are not known to php unless provided to it. Otherwise, PHP does not care about the browser in the least.

JaymeNYC
02-16-2010, 05:39 PM
The only way to check if JS is enabled is to use js to set a cookie and let php retrieve it. Otherwise, you cannot detect this. My first post in this thread indicated that browser specific configurations are not known to php unless provided to it. Otherwise, PHP does not care about the browser in the least.

What would u say is the best way to get the IP,Browser Type, and OS Version?

Fou-Lu
02-16-2010, 05:45 PM
Those three can be retrieved from the REMOTE_ADDR and HTTP_REFERER. Both are technically spoofable, but not really a big deal to be quite honest.
The splitting up of information for the HTTP_REFERER is where get_browser is quite handy. OS version is included as a result under 'platform', and 'browser' for the browser type.
With IP, you can try to get a more accurate reading by implementing techniques using HTTP_VIA and HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR and whatnots. These help to eliminate things like proxy servers and internal NAT translations on lans. Just google up for 'determine real IP with php' or something like that, and you should get a few articles regarding the usage of these.

_Aerospace_Eng_
02-16-2010, 05:53 PM
These may be useful to you.

http://techpatterns.com/downloads/php_browser_detection.php

JaymeNYC
02-16-2010, 08:16 PM
These may be useful to you.

http://techpatterns.com/downloads/php_browser_detection.php

ill try this out soon thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum