[PHP] Simple Scripts Deteksi Alamat IP, Browser dan OS visitor
by Admin in HTML, PHP, PROGRAMMING 0
=======================================================
====================================================
Berikut scripts untuk menamplkan ke HTML
====================================================
<?php
/**
* @author HandoYo
* @Copyright (c) 2011 vM Crew (handoyo1989@gmail.com)
*/
class Browser {
public static function detect() {
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (preg_match('/opera/', $userAgent)) {
$name = 'Opera';
}
elseif (preg_match('/webkit/', $userAgent)) {
$name = 'Safari/Chrome';
}
elseif (preg_match('/msie/', $userAgent)) {
$name = 'Internet Explorer';
}
elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
$name = 'Mozilla Firefox';
}
else {
$name = 'unrecognized';
}
if (preg_match('/.+(?:fox|it|ra|ie)[\/: ]([\d.]+)/', $userAgent, $matches)) {
$version = $matches[1];
}
else {
$version = 'unknown';
}
if (preg_match('/linux/', $userAgent)) {
$platform = 'linux';
}
elseif (preg_match('/macintosh|mac os x/', $userAgent)) {
$platform = 'mac';
}
elseif (preg_match('/windows|win32/', $userAgent)) {
$platform = 'Windows';
}
else {
$platform = 'unrecognized';
}
return array(
'name' => $name,
'version' => $version,
'platform' => $platform,
'userAgent' => $userAgent
);
}
}
$browser = Browser::detect();
$rip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$engine = $_SERVER['HTTP_VIA'];
$ip = $_SERVER['REMOTE_ADDR'];
?>
====================================================
Berikut scripts untuk menamplkan ke HTML
====================================================
<table border="0" width="100%" style="border-collapse: collapse">
<tr>
<td width="141">Browser Name</td>
<td width="11">:</td>
<td><?php echo $browser['name']; ?>/<?php echo $browser['version']; ?></td>
</tr>
<tr>
<td>OS Platform</td>
<td>:</td>
<td><?php echo $browser['platform']; ?></td>
</tr>
<tr>
<td>IP</td>
<td>:</td>
<td><?php echo $ip ?></td>
</tr>
<tr>
<td>Agent</td>
<td>:</td>
<td><?php echo $browser['userAgent']; ?></td>
</tr>
</table>
======================================================