<?php
/**************************************************/
/*
Released by AwesomePHP.com, under the GPL License, a
copy of it should be attached to the zip file, or
you can view it on http://AwesomePHP.com/gpl.txt
*/
/**************************************************/
/*
User Info:
---------
* Get User Browser/Version
* Get User Operating System
* Get User IP
* Get User Country
* Get System Language
* Check For Flash
* Check For JavaScript
* Check User Speed
*/
class getUserInfo{
/* Variables */
private $userIP;
private $userAgent;
private $isCookiePut;
/* Get User IP */
function getIP(){return $this->userIP;}
/* Set User IP */
function setIP()
{
$ipParts = explode(".", $_SERVER["REMOTE_ADDR"]);
if ($ipParts[0] == "165" && $ipParts[1] == "21") {
if (getenv("HTTP_CLIENT_IP")) {
$this->userIP = getenv("HTTP_CLIENT_IP");
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
$this->userIP = getenv("HTTP_X_FORWARDED_FOR");
} elseif (getenv("REMOTE_ADDR")) {
$this->userIP = getenv("REMOTE_ADDR");
}
} else {
$this->userIP = $_SERVER["REMOTE_ADDR"];
}
if($this->userIP == NULL){ return 'Unknown';}
}
/* Set User Agent */
function setAgent(){$this->userAgent = $this->getAgent();}
/* Get User Referreal */
function getReferer()
{
if($_SERVER["HTTP_REFERER"]){
return $_SERVER["HTTP_REFERER"];
}
if(getenv("HTTP_REFERER")){
return getenv("HTTP_REFERER");
}
return 'Unknown';
}
/* Get User Operating System */
function getSystem()
{
$userInfo = $this->userAgent;
if (preg_match("/windows nt 6/i",$userInfo)) return 'Windows Vista';
elseif (preg_match("/windows nt 5.1/i",$userInfo)) return 'Windows XP';
elseif (preg_match("/windows xp/i",$userInfo)) return 'Windows XP';
elseif (preg_match("/linux/i",$userInfo)) return 'Linux';
elseif (preg_match("/macintosh/i",$userInfo)) return 'Macintosh';
elseif (preg_match("/win 9x 4.90/i",$userInfo)) return 'Windows ME';
elseif (preg_match("/windows me/i",$userInfo)) return 'Windows ME';
elseif (preg_match("/windows nt 5.0/i",$userInfo)) return 'Windows 2000';
elseif (preg_match("/windows 2000/i",$userInfo)) return 'Windows 2000';
elseif (preg_match("/windows nt 3.1/i",$userInfo)) return 'Windows 3.1';
elseif (preg_match("/windows nt 3.5.0/i",$userInfo)) return 'Windows 3.5';
elseif (preg_match("/windows nt 3.5.1/i",$userInfo)) return 'Windows 3.51';
elseif (preg_match("/windows nt 4.0/i",$userInfo)) return 'Windows NT 4.0';
elseif (preg_match("/windows 98/i",$userInfo)) return 'Windows 98';
elseif (preg_match("/windows 95/i",$userInfo)) return 'Windows 95';
elseif (preg_match("/sunos/i",$userInfo)) return 'Sun';
else return 'Unknown';
}
/* Get User Browser */
function getBrowser()
{
$userInfo = $this->userAgent;
require_once('helper.folder/browserList.php');
foreach($explorerTypes as $sub => $name){
if(eregi($explorerTokens[$sub],$userInfo)){ return $name;}
}
return 'Unknown';
}
/* Function Get Search Engine Name */
function getEngine()
{
$url = parse_url($this->getReferer());
if(!$url){ return 'Unknown';}
if(eregi('google',$url['host']) && eregi('url=',$url['query'])){
return 'Google Search';
}
if(eregi('yahoo.com',$url['host']) && eregi('q=',$url['query'])){
return 'Yahoo Search';
}
if(eregi('ask.com',$url['host']) && eregi('q=',$url['query'])){
return 'Ask Search';
}
if(eregi('alltheweb.com',$url['host']) && eregi('q=',$url['query'])){
return 'All The Web Search';
}
if(eregi('aol.com',$url['host']) && eregi('query=',$url['query'])){
return 'AOL Search';
}
if(eregi('hotbot.com',$url['host']) && eregi('query=',$url['query'])){
return 'Hot Bot';
}
if(eregi('teoma.com',$url['host']) && eregi('q=',$url['query'])){
return 'Teoma';
}
if(eregi('altavista.com',$url['host']) && eregi('q=',$url['query'])){
return 'Alta Vista Search';
}
if(eregi('gigablast.com',$url['host']) && eregi('q=',$url['query'])){
return 'Giga Blast';
}
if(eregi('looksmart.com',$url['host']) && eregi('qt=',$url['query'])){
return 'Look Smart';
}
if(eregi('lycos.com',$url['host']) && eregi('query=',$url['query'])){
return 'Lycos Search';
}
if(eregi('msn.com',$url['host']) && eregi('q=',$url['query'])){
return 'MSN Search';
}
if(eregi('netscape.com',$url['host']) && eregi('query=',$url['query'])){
return 'Netscape Search';
}
if(eregi('dmoz.org',$url['host']) && eregi('q=',$url['query'])){
return 'DMOZ';
}
if(eregi('excite.com',$url['host']) && eregi('/search/web/',$url['query'])){
return 'Excite';
}
if(eregi('alexa.com',$url['host']) && eregi('q=',$url['query'])){
return 'Alexa';
}
if(eregi('a9.com',$url['host']) && eregi('http://a9.com',$url['host'])){
return 'A9';
}
return 'Unknown';
}
/* Get Country Name Function */
function getCountry()
{
/*
To use this function, insure that a current mysql database connection exist
and that you have downloaded CSV file:
http://www.maxmind.com/app/geolitecountry
and ran file installDatabase.php located in the helper.folder
*/
$this->userIP = '76.112.156.26';
if(!$this->checkIP()){ return 'Intranet/Localhost';}
$temp = explode('.',$this->userIP);
$ipnum = 16777216*$temp[0] + 65536*$temp[1] + 256*$temp[2] + $temp[3];
$getCountry = mysql_fetch_assoc(mysql_query("SELECT `country_name` FROM `geo_ip`
WHERE '$ipnum' >= `begin_num` AND '$ipnum' <= `end_num`"));
return $getCountry['country_name'];
}
/* Function to get language */
function getLanguage()
{
$languageCode = array('af', 'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'fi', 'fr', 'gl', 'he', 'hi', 'hr', 'hu',
'id', 'it', 'ja', 'ko', 'ka', 'lt', 'lv', 'ms', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sq', 'sr', 'sv',
'th', 'tr', 'uk', 'zh');
$languageName = array('Afrikaans', 'Arabic', 'Bulgarian', 'Catalan', 'Czech', 'Danish', 'German', 'Greek', 'English',
'Spanish', 'Estonian', 'Finnish', 'French', 'Galician', 'Hebrew', 'Hindi', 'Croatian', 'Hungarian',
'Indonesian', 'Italian', 'Japanese', 'Korean', 'Georgian', 'Lithuanian', 'Latvian', 'Malay',
'Dutch', 'Norwegian', 'Polish', 'Portuguese', 'Romanian', 'Russian', 'Slovak', 'Slovenian', 'Albanian',
'Serbian', 'Swedish', 'Thai', 'Turkish', 'Ukrainian', 'Chinese');
$thisLang = strtolower($this->acceptLanguage());
$thisAgent = strtolower($this->userAgent);
foreach($languageCode as $sub => $langCode){
if(strpos($thisLang, $langCode) === 0 ||
strpos($thisLang, $langCode) !== false ||
preg_match("/[\[\( ]{$langCode}[;,_\-\)]/",$thisAgent)) {
return array($langCode,$languageName[$sub]);
}
}
return 'Unknown';
}
/*
Function to Print HTML to check for Flash
Stores Cookie Name: isFlash (which has values yes/no)
*/
function printFlashHTML()
{
echo '<!-- begin the OBJECT tag, which will be understood by ActiveX-capable browsers -->
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
CODEBASE="http://active.macromedia.com/flash/cabs/swflash.cab#version=3,0,0,11"
WIDTH="1" HEIGHT="1" NAME="sw" ID="sw">
<PARAM NAME="quality" VALUE="high">
<PARAM NAME="Loop" VALUE="true">
<PARAM NAME="play" VALUE="true">
<!-- begin the JavaScript -->
<SCRIPT LANGUAGE="JavaScript">
'.$this->printJSCookieCreator().'
//If this browser understands the mimeTypes property and recognizes the MIME Type //"application/x-shockwave-flash"...
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]){
// Flash is active
createCookie(\'isFlash\',\'yes\',\'100\');
}
//Otherwise,...
else {
// No flash
createCookie(\'isFlash\',\'no\',\'100\');
}
</SCRIPT>
<!-- Close the OBJECT tag. -->
</OBJECT>';
$this->isCookiePut = true;
}
/* Check for Javascript */
function checkJavaFlashCookie()
{
if($this->isCookiePut == false){
echo $this->printJSCookieCreator();
}
return ($_COOKIE['isFlash'] == 'yes');
}
/* Print Javascript Cookie Creator - private */
private function printJSCookieCreator()
{
return 'function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}';
}
/*
Function to check user speed
Stored in cooike speedKBPS, in Kbps format
*/
function getSpeed()
{
$kbytes = 100;
$chars = array_map("chr", range(0x20, 0x7e));
for ($j = 0; $j < $kbytes * 1000; $j++) {
$text .= $chars[intval(rand(0, count($chars)))];
}
$text = preg_replace('/[<>!&]/', '.', $text);
echo '<script Language="JavaScript">
var DataSize = '.$kbytes.';
var startTime = new Date().getTime();
</script>
<!-- '.$text.' -->
<script Language="JavaScript">
var endTime = new Date().getTime();
var loadingTime = (endTime - startTime) / 1000; // sec
function bps(s, t) {
var b = s * 8; // byte to bit
var r = b / t;
if (r < 10) r = Math.round(r * 10) / 10
else r = Math.round(r);
return r;
}';
echo $this->printJSCookieCreator();
echo "\n\tcreateCookie('speedKBPS',bps(DataSize,loadingTime),'100');\n</script>";
return number_format(ceil($_COOKIE['speedKBPS']));
}
/* Get user Agent String - private */
private function getAgent()
{
if($_SERVER["HTTP_USER_AGENT"]){
return $_SERVER["HTTP_USER_AGENT"];
}
if(getenv("HTTP_USER_AGENT")){
return getenv("HTTP_USER_AGENT");
}
return false;
}
/* Get User Language - private */
private function acceptLanguage()
{
if($_SERVER["HTTP_ACCEPT_LANGUAGE"]){
return $_SERVER["HTTP_ACCEPT_LANGUAGE"];
}
if(getenv("HTTP_ACCEPT_LANGUAGE")){
return getenv("HTTP_ACCEPT_LANGUAGE");
}
return 'Unknown';
}
/* Check for localhost */
private function checkIP(){
if (!empty($this->userIP) && $this->userIP == long2ip(ip2long($this->userIP))) {
$reserved_ips = array (
array('0.0.0.0','2.255.255.255'),
array('10.0.0.0','10.255.255.255'),
array('127.0.0.0','127.255.255.255'),
array('169.254.0.0','169.254.255.255'),
array('172.16.0.0','172.31.255.255'),
array('192.0.2.0','192.0.2.255'),
array('192.168.0.0','192.168.255.255'),
array('255.255.255.0','255.255.255.255')
);
foreach ($reserved_ips as $r){
$min = ip2long($r[0]);
$max = ip2long($r[1]);
if ((ip2long($this->userIP) >= $min)
&& (ip2long($this->userIP) <= $max)) {return false;}
}
return true;
}
return false;
}
/* Call PreSets */
function loadSystem()
{
$this->setIP();
$this->setAgent();
$this->isCookiePut = false;
}
}
?>