General Community > Scripting Help

Finding the users browser and OS?

(1/2) > >>

۞:
I've seen it in people sig's and i was just wondering how its done..

Aquilo:
<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>

is the way to grab it then you can use things like preg_match() to get the parts.

۞:
ohh.. ok. Thanks.

Seph|roth:

--- Quote from: Aquilo on September 06, 2003, 01:57:44 PM ---<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>

is the way to grab it then you can use things like preg_match() to get the parts.

--- End quote ---
and how does preg_match() work?

Aquilo:
here is a really cool script to do it for ya'll!

I got you the address to since it takes a bit to find it!

http://sourceforge.net/projects/phpsniff/

there is an example page in the download with every
thing you could ever want and the code to get it to
the left of the output!

but what the heck - here is the code you'll need for
a sig pic all nice and formated. just download the
class and past this at the top of your sig script,
remember to edit the require_once to your system
path - and I listed the variables you'll wan't!!!


--- Code: ---/**************************************************/
/************** initialize some vars **************/

require_once ('/home/user/public_html/full_path/phpSniff.class.php');

   $GET_VARS   = isset ($_GET)  ? $_GET : $HTTP_GET_VARS;
   $POST_VARS   = isset ($_POST) ? $_GET : $HTTP_POST_VARS;
   $GET_VARS['UA'] = empty ($GET_VARS['UA']) ? '' : $GET_VARS['UA'];
   $GET_VARS['cc'] = empty ($GET_VARS['cc']) ? '' : $GET_VARS['cc'];
   $GET_VARS['dl'] = empty ($GET_VARS['dl']) ? '' : $GET_VARS['dl'];
   $GET_VARS['am'] = empty ($GET_VARS['am']) ? '' : $GET_VARS['am'];

   $sniffer_settings = array(
      'check_cookies'      => $GET_VARS['cc'],
      'default_language'   => $GET_VARS['dl'],
      'allow_masquerading'   => $GET_VARS['am'] );

   $client =& new phpSniff($GET_VARS['UA'], $sniffer_settings);

   $agt   = strtoupper ( $client->property('long_name') . ' ' . $client->property('version') );
   $os   = strtoupper ( (($xt = $client->property('platform')) == "win" ?
            "Windows" : $xt) . ' ' . $client->property('os') );

   $ipx   = getenv("HTTP_CLIENT_IP") ? getenv("HTTP_CLIENT_IP") : 0 ;
   $ipx   = (!$ipx && getenv("HTTP_X_FORWARDED_FOR")) ? getenv("HTTP_X_FORWARDED_FOR") : 0 ;
   $ipx   = (!$ipx && getenv("REMOTE_ADDR")) ? getenv("REMOTE_ADDR") : 0 ;
   $ip   = (!$ipx) ? "UNKNOWN" : $ipx;

   $host   = @GetHostByAddr($ip);
   $host   = explode(".", $host);
   $isp   = ($ip != "UNKNOWN") ? $host[$c=count($host)-2].'.'.$host[$c+1] : "UNKNOWN";

/************** initialize some vars **************/
/**************************************************/

--- End code ---

$agt will be the browser...
$os will be the operating system...
$ip will be the number address...
$isp will be there internet service provider...

[EDIT] 9 - 16 - 2003 fixed a typo

Navigation

[0] Message Index

[#] Next page

Go to full version