Currently, the class Opc_Visit provides the following information:
- IP address
- Host address
- Current request addresses, paths, file names, all server-independent, mod_rewrite-independent etc.
- Accepted browser languages, sorted by the priority.
- Cookie server and cookie path detection.
- Protocol and port detection.
- Browser detection (recognizes 26 browsers and search engines)
- Operating system detection (recognizes 10 Windows versions, 14 Linux distributions and 7 other Unix clones, including MacOS).
Below, we can see a sample test script output called on my computer as http://opl.libs.lh/trunk/dev/opc/test_visit.php/foo?bar=joe:
IP: 127.0.0.1 numericIP: 2130706433 host: localhost.localdomain currentAddress: http://opl.libs.lh/trunk/dev/opc/test_visit.php/foo?bar=joe currentFile: http://opl.libs.lh/trunk/dev/opc/test_visit.php currentParams: /foo currentPath: http://opl.libs.lh/trunk/dev/opc/ fileName: test_visit.php pathInfo: /foo?bar=joe protocol: http port: 80 secure: false languages: array ( 0 => 'pl-PL', 1 => 'pl', 2 => 'en', ) browser: Opera 9.52 OS: Arch Linux cookieServer: opl.libs.lh cookiePath: /trunk/dev/opc/
The class API is more than simple:
php
<?php
// OPL Initialization
require('../../lib/opl/base.php');
Opl_Loader::setDirectory('../../lib/');
Opl_Registry::setState('opl_debug_console', true);
spl_autoload_register(array('Opl_Loader', 'autoload'));
try
{
$visit = Opc_Visit::getInstance();
$paramList = array(0 =>
'IP', 'numericIP', 'host', 'currentAddress', 'currentFile', 'currentParams', 'currentPath', 'fileName',
'pathInfo', 'protocol', 'port', 'secure', 'languages', 'browser', 'OS', 'cookieServer', 'cookiePath');
echo '<ol>';
foreach($paramList as $par)
{
$value = $visit->$par;
if(is_bool($value))
{
$value = ($value ? 'true' : 'false');
}
elseif(is_array($value))
{
$value = var_export($value, true);
}
echo '<li>'.$par.': <code>'.$value.'</code></li>';
}
echo '</ol>';
}
catch(Opl_Exception $e)
{
Opl_Error_Handler($e);
}
?>
We have here the singleton implementation and the magic __get method used to generate and return the requested values.
The class will be available in our SVN repository tomorrow or on Thursday, because I must clean up the code and add the recent inventions, such as Google Chrome or Windows Vista to the detectors.
Last comments