Guys, right now I'm developing a web traffic analysis coding. So, the problem is that my php syntax can't read the browser type and version (i.e Internet Explorer 6, Mozilla/5). It only displayed unknown. This also occured when the coding tried the OS version (i.e Windows 2000, XP, Linux). Below is the coding i used;
For the browser;
$browser_search = array("MSIE 6.0", "MSIE 5.5", "MSIE 5.0", "MSIE 4.0","Opera","Konqueror","Mozilla/5.0", "Mozilla/4", "Mozilla"); $browser = array("Internet Explorer 6","Internet Explorer 5.5", "Internet Explorer 5", "Internet Explorer 4", "Opera","Konqueror","Netscape 6.x", "Netscape 4.x", "Netscape"); $u_referrer = @getenv("HTTP_REFERER"); if (empty($u_referrer) == true) { $u_referrer = 'Bookmark or other'; } $u_page = @getenv("SCRIPT_NAME"); if (empty($u_page) == true) { $u_page = 'Direct link to counter'; } $other = 1; while(list($key, $value) = each ($browser_search)) { $pos = strpos ($HTTP_USER_AGENT, $value); if($pos !== false){ $IBROWSER = $browser[$key]; $other = 0; break 1; } } if($other != "0"){ $IBROWSER = "Unknown"; } $other = 1; while(list($key, $value) = each ($os_search)) { $pos = strpos ($HTTP_USER_AGENT, $value); if($pos !== false){ $OPSYS = $os[$key]; $other = 0; break 1; }
For the OS;
$os_search = array("Windows 2000", "Windows 98", "Windows 95", "Win95", "Win98", "Windows NT 4.0", "Windows NT 5.0", "Windows NT 5.1", "Windows XP", "Windows ME", "WinNT", "Mac_PowerPC", "Macintosh", "SunOS", "Linux", "Windows NT"); $os = array("Windows 2000", "Windows 98", "Windows 95", "Windows 95", "Windows 98", "Windows NT 4.0", "Windows NT 5.0", "Windows XP", "Windows XP", "Windows ME", "WinNT", "Macintosh", "Macintosh", "SunOS", "Linux", "WinNT"); if($other != "0"){ $IBROWSER = "Unknown"; } $other = 1; while(list($key, $value) = each ($os_search)) { $pos = strpos ($HTTP_USER_AGENT, $value); if($pos !== false){ $OPSYS = $os[$key]; $other = 0; break 1; } } if($other != 0){ $OPSYS = "Unknown"; } $HOSTMASK = gethostbyaddr($ip); $query ="INSERT INTO $SQL_LOGTABLE (SC_TIMESTAMP ,SC_IP ,SC_HOST ,SC_BROWSER ,SC_OS ,SC_LANGUAGE ,SC_REFFERER ,SC_PAGE) VALUES (\"$time\",\"$ip\",\"$HOSTMASK\",\"$IBROWSER\",\"$OPSYS\",\"$u_lang\",\"$u_referrer\",\"$u_page\")"; $result = mysql_query($query) or die(mysql_error());
The syntax also included to read the visitor's IP address, which is doesn't have any problem. The problem lies with browser and OS read syntax. Help me guys. Thanks in advanced