/    Sign up×
Community /Pin to ProfileBookmark

Detect Client info with PHP

There are a few things I would like to have access to about the client, like screen size, color depth, etc.. I’ve found these things in the past with Javascript, but I’d like to see what I can get with PHP functions. I know I can grab the IP address through the pre-defined $_SERVER array, which is nice to have in my custom logs so i can ignore the parts that have my IP. However, since some of the people who visit my site have really old computers, a lack of proper color depth or really small screen resolutions aren’t unlikely. Also, It would be nice to know which people are using their Macs and which aren’t. Any ideas for what I could use to find this kind of stuff? Please and Thanks!

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@LeeUJul 13.2006 — You can find a PHP Browser detection & OS detection script [URL=http://techpatterns.com/downloads/php_browser_detection.php]here[/URL]. And more [URL=http://www.phpbuilder.com/columns/tim20000821.php3]here[/URL].
Copy linkTweet thisAlerts:
@AmazingAntauthorJul 13.2006 — Thanks Lee!
Copy linkTweet thisAlerts:
@NogDogJul 13.2006 — Also take a look at the [url=http://www.php.net/manual/en/function.get-browser.php]get_browser() function[/url].
Copy linkTweet thisAlerts:
@balloonbuffoonJul 13.2006 — In my experience, [url=http://www.php.net/manual/en/function.get-browser.php]get_browser()[/url] has proven to be very unreliable. Its best to try and parse $_SERVER['HTTP_USER_AGENT'] yourself. (Or use a premade script.)

--Steve
Copy linkTweet thisAlerts:
@AmazingAntauthorJul 13.2006 — Wow, that's actually [I]not[/I] something I would have thought of. No sarcasm or anything. Thanks NogDog! I'll be sure to check out the $_SERVER['HTTP_USER_AGENT'] too.
Copy linkTweet thisAlerts:
@NogDogJul 13.2006 — get_browser() will only be as good or bad as the browscap.ini file you use for it (and which is not part of the standard PHP distribution).
Copy linkTweet thisAlerts:
@AmazingAntauthorJul 14.2006 — That's definatly something I should pay attention to then. In the php manual, it has a link to [URL=http://browsers.garykeith.com/downloads.asp]this[/URL] site. Do you know if this is a good/bad browscap.ini to use? I just got the php-specific one and re-named it to work. Now unfortunatly, it would seem that my php doesn't want to find it anyway. I went ahead and tryed to find the php.ini, and it was in the main windows directory. I found the line that looks like this:

[browscap]

;browscap = extra/browscap.ini

and changed it to this:

[browscap]

browscap = C:/WINDOWS/system32/inetsrv/browscap.ini

which is where I put the browscap file, as instructed by that site. So, as the site also suggested, I restarted the apache server, and tryed the sample code that the php manual has for the get_browser function. It told me what browser I have and a little more through the $_SERVER['HTTP_USER_AGENT'], but then it says



Warning: get_browser() [function.get-browser]: browscap ini directive not set. in C:Documents and Settings***********My Documentsweb servermeh.php on line 4
[/quote]


Like I said, I just copied the example code from the manual, and that's all the contents of the meh.php file.

So far, I've gotta agree that the $_SERVER['HTTP_USER_AGENT'] is much easier to setup, even if it is less helpful. I can't so much agree that it's more reliable, knowing that the get_browser hasn't even worked for me yet, but it's looking like I'll end up agreeing soon enough. Thanks again for helping, if only I could stop [I]trying[/I] to find all the hard problems.... :rolleyes:
Copy linkTweet thisAlerts:
@NogDogJul 14.2006 — I think you need to use back-slashes in your path. This is what's in my php.ini file:
<i>
</i>[browscap]
browscap = "C:Program Filesxamppphpbrowscapbrowscap.ini"

...and get_browser() worked fine for me.
Copy linkTweet thisAlerts:
@felgallJul 14.2006 — The user agent is user configurable and so can contain anything at all so don't rely on it for anything that you need to be accurate.
Copy linkTweet thisAlerts:
@AmazingAntauthorJul 14.2006 — I suppose that's true, felgall. Nog-I went ahead and copied that line out of your code box and pasted it into the php.ini, and of course changed the location. Still nothing. I guess i'm just gonna have to live with the $_SERVER['HTTP_USER_AGENT']... as much as it sucks to have to do that... Thanks for trying Nogdog.
Copy linkTweet thisAlerts:
@NogDogJul 14.2006 — After the change, did you restart Apache? Also, did you select the browscap.ini file that says it's for PHP (and not one of them that says it's NOT for PHP?).
Copy linkTweet thisAlerts:
@AmazingAntauthorJul 14.2006 — After the change, did you restart Apache? Also, did you select the browscap.ini file that says it's for PHP (and not one of them that says it's NOT for PHP?).[/QUOTE]
Yes, I went ahead and made sure to restart each time I changed it in any way. Being annoied at it, I even tryed restarting twice, which didn't help at all. As to it being the correct file, I grabbed the one named php_browscap.ini, and renamed it to just browscap.ini as the site said to. Where's MSN messenger with the smiley that bangs it's head into a brick wall? I could really use that one right now...

It would be nice if computers and their programs worked the first time... But then, I suppose we'd be living with the computers making programming languages and writing the code themselves, and that wouldn't be much fun when they got to taking over the internet....
×

Success!

Help @AmazingAnt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...