Example #1
0
function jal_get_useronline_engine($usertimeout = 60)
{
    global $shout_tb;
    $tableuseronline = $shout_tb . 'liveshoutbox_useronline';
    $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_NAME, $conn);
    @mysql_query("SET CHARACTER SET 'utf8'", $conn);
    @mysql_query("SET NAMES utf8", $conn);
    // Search Bots
    $bots = array('Google' => 'googlebot', 'Bing' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');
    // Useronline Settings
    $timeoutseconds = $usertimeout;
    $timestamp = time();
    $timeout = $timestamp - $timeoutseconds;
    // Check Members
    if (isset($_COOKIE['jalUserName']) && strtolower(substr($_COOKIE['jalUserName'], 0, 4)) != strtolower(substr(trim($_SESSION['guest']), 0, 4))) {
        $memberonline = mysql_real_escape_string(str_replace("\\'", "'", $_COOKIE['jalUserName']));
        $where = "WHERE username='******'";
    } else {
        // guestify the user
        $memberonline = 'guest';
        $where = "WHERE username='******' AND ip='" . jal_get_IP() . "'";
    }
    // Check For Bot
    foreach ($bots as $name => $lookfor) {
        if (stristr($_SERVER['HTTP_USER_AGENT'], $lookfor) !== false) {
            $memberonline = mysql_real_escape_string($name);
            $where = "WHERE ip='" . jal_get_IP() . "'";
        }
    }
    $visitinguri = $_SERVER['REQUEST_URI'];
    if (str_replace("/wordspew.php", "", $_SERVER['REQUEST_URI']) != $_SERVER['REQUEST_URI']) {
        $visitinguri = null;
    }
    mysql_query("LOCK TABLES {$tableuseronline} WRITE", $conn);
    if (!in_array(strtolower($memberonline), $_SESSION['HideUsers' . $shout_tb])) {
        $sql = "UPDATE {$tableuseronline} SET timestamp = '{$timestamp}', ip = '" . jal_get_IP() . "' {$where}";
        mysql_query($sql, $conn);
    }
    // If No User Insert It
    if (mysql_affected_rows($conn) == 0) {
        if (!in_array(strtolower($memberonline), $_SESSION['HideUsers' . $shout_tb])) {
            $sql = "INSERT INTO {$tableuseronline} VALUES ('{$timestamp}', '{$memberonline}', '" . jal_get_IP() . "', '', '/')";
            mysql_query($sql, $conn);
        }
    }
    $sql = "DELETE FROM {$tableuseronline} WHERE timestamp < {$timeout}";
    mysql_query($sql, $conn);
    mysql_query("UNLOCK TABLES", $conn);
    $result = mysql_query("SELECT username FROM {$tableuseronline}", $conn);
    $useronline = array();
    while ($element = mysql_fetch_array($result)) {
        $useronline[] = $element["username"];
    }
    $detected_bots = array();
    $registered_users = array();
    $guests = 0;
    foreach ($useronline as $element) {
        if (array_key_exists($element, $bots)) {
            $detected_bots[] = $element;
        } elseif ($element == "guest") {
            $guests = $guests + 1;
        } else {
            if (!in_array(strtolower($element), $_SESSION['HideUsers' . $shout_tb])) {
                $registered_users[] = $element;
            }
        }
    }
    if (!defined("DB_CHARSET")) {
        @mysql_query("SET CHARACTER SET 'latin1'", $conn);
        @mysql_query("SET NAMES latin1", $conn);
    }
    return array("num_guests" => $guests, "bots" => $detected_bots, "users" => $registered_users);
}
Example #2
0
function jal_get_useronline_engine($usertimeout = 60) {
	global $jal_table_prefix;
	$tableuseronline = $jal_table_prefix.'liveshoutbox_useronline';

	$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	mysql_select_db(DB_NAME, $conn);
	@mysql_query("SET CHARACTER SET 'utf8'", $conn);
	@mysql_query("SET NAMES utf8", $conn);

	// Search Bots
	$bots = array('Google' => 'googlebot', 'MSN' => 'msnbot', 'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'askjeeves', 'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi', 'Turnitin.com' => 'turnitinbot');

	// Useronline Settings
	$timeoutseconds = $usertimeout;
	$timestamp = time();
	$timeout = $timestamp-$timeoutseconds;

	$sql = "SELECT option_value from {$jal_table_prefix}options where option_name = 'siteurl'";
	$result = mysql_query($sql,$conn);
	while($element = mysql_fetch_array($result)) $siteurl = $element["option_value"];

	// Check Members
	if(isset($_COOKIE['jalUserName']) && (strtolower(substr($_COOKIE['jalUserName'],0,4)) != strtolower(substr(trim($_SESSION['guest']),0,4)))) {
			$memberonline = mysql_real_escape_string(str_replace("\'", "'", $_COOKIE['jalUserName']));
			$where = "WHERE username='******'";
	} else { // guestify the user
		$memberonline = 'guest';
		$where = "WHERE ip='".jal_get_IP()."'";
	}
	// Check For Bot
	foreach ($bots as $name => $lookfor) {
		if (stristr($_SERVER['HTTP_USER_AGENT'], $lookfor) !== false) { 
			$memberonline = mysql_real_escape_string($name);
			$where = "WHERE ip='".jal_get_IP()."'";
		} 
	} 
	$make_page = "(unknown page title)";
	$visitinguri = $_SERVER['REQUEST_URI'];
	if (str_replace("/wordspew.php","",$_SERVER['REQUEST_URI']) != $_SERVER['REQUEST_URI'])
		$visitinguri = null;

	$s = ""; foreach ($_COOKIE as $key=>$val) { $s.="[$key]='$val' --- "; }
	$s = "Live chat: username detected: '" . $memberonline . "' --- cookie: " .$s;

	mysql_query("LOCK TABLES $tableuseronline WRITE", $conn);	

	if ($visitinguri != null)
		mysql_query("UPDATE $tableuseronline SET timestamp = '$timestamp', ip = '".jal_get_IP()."', location = '".mysql_real_escape_string($make_page)."', url = '".mysql_real_escape_string($visitinguri)."' $where", $conn);
	else
		mysql_query("UPDATE $tableuseronline SET timestamp = '$timestamp', ip = '".jal_get_IP()."' $where", $conn);

	// If No User Insert It
	if (mysql_affected_rows($conn) == 0) {
		if ($visitinguri != null)
			mysql_query("INSERT INTO $tableuseronline VALUES ('$timestamp', '$memberonline', '".jal_get_IP()."', '".mysql_real_escape_string($make_page)."', '".mysql_real_escape_string($visitinguri)."')",$conn);
		else 
			mysql_query("INSERT INTO $tableuseronline VALUES ('$timestamp', '$memberonline', '".jal_get_IP()."', NULL,NULL)",$conn);
	}

	mysql_query("DELETE FROM $tableuseronline WHERE timestamp < $timeout",$conn);
	mysql_query("UNLOCK TABLES", $conn);

	$result = mysql_query("SELECT username FROM $tableuseronline",$conn);

	$useronline = array();
	while($element = mysql_fetch_array($result)) $useronline[] = $element["username"];

	$detected_bots = array();
	$registered_users = array();
	$guests = 0;
	foreach ($useronline as $element) {
		if (array_key_exists($element,$bots)) $detected_bots[] = $element;
		elseif ($element == "guest") $guests = $guests + 1;
		else $registered_users[] = $element;
	}
	if (!defined("DB_CHARSET")) {
		@mysql_query("SET CHARACTER SET 'latin1'", $conn);
		@mysql_query("SET NAMES latin1", $conn);
	}
	return array("num_guests"=>$guests,"bots"=>$detected_bots,"users"=>$registered_users);
}