' . join('|', $known) . ')[/ ]+(?[0-9.|a-zA-Z.]*)#'; if (!preg_match_all($pattern, $useragent, $matches)) { // we have no matching number just continue } // see how many we have $i = count($matches['browser']); if ($i != 1) { //we will have two since we are not using 'other' argument yet //see if version is before or after the name if (strripos($useragent, "Version") < strripos($useragent, $ub)) { $version = $matches['version'][0]; } else { $version = $matches['version'][1]; } } else { $version = $matches['version'][0]; } // check if we have a number if ($version == null || $version == "") { $version = "?"; } return array( 'ipaddress' => $ipaddress, 'useragent' => $useragent, 'browser' => $bname, 'version' => $version, 'platform' => $platform ); } public static function createOrReferenceTerminalDbEntry($pdo,$terminalInfo) { $sql = "SELECT id FROM %terminals% WHERE ipaddress=? AND useragent=? AND browser=? AND version=? AND platform=?"; $result = CommonUtils::fetchSqlAll($pdo, $sql, array($terminalInfo['ipaddress'],$terminalInfo['useragent'],$terminalInfo['browser'],$terminalInfo['version'],$terminalInfo['platform'])); if (count($result) > 0) { return $result[0]['id']; } else { $sql = "INSERT INTO %terminals% (ipaddress,useragent,browser,version,platform) VALUES(?,?,?,?,?)"; CommonUtils::execSql($pdo, $sql, array($terminalInfo['ipaddress'],$terminalInfo['useragent'],$terminalInfo['browser'],$terminalInfo['version'],$terminalInfo['platform'])); return $pdo->lastInsertId(); } } }