<?php
/* Определение IP-адресса посетителя */
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and preg_match('|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$|',$_SERVER['HTTP_X_FORWARDED_FOR']))
{
	$ip = trim(htmlspecialchars(mysql_real_escape_string($_SERVER['HTTP_X_FORWARDED_FOR'])));
}
elseif(isset($_SERVER['HTTP_CLIENT_IP']) and preg_match('|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$|',$_SERVER['HTTP_CLIENT_IP']))
{
	$ip = trim(htmlspecialchars(mysql_real_escape_string($_SERVER['HTTP_CLIENT_IP'])));
}
elseif(isset($_SERVER['REMOTE_ADDR']) and preg_match('|^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$|',$_SERVER['REMOTE_ADDR']))
{
	$ip = trim(htmlspecialchars(mysql_real_escape_string($_SERVER['REMOTE_ADDR'])));
}
else
{
	$ip = 'скрыт';
}
/* Определение UA посетителя */
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']))
{
	$ua = trim(stripcslashes(htmlspecialchars(mysql_real_escape_string($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']))));
}
elseif (isset($_SERVER['HTTP_USER_AGENT']))
{
	$ua = trim(stripcslashes(htmlspecialchars(mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']))));
}
else
{
	$ua = 'скрыт';
}
$ua=strtok($ua, '/');
$ua=strtok($ua, ' ');
//////////////////////////////
if($user['id']<1){
$online_q = mysql_fetch_assoc(mysql_query("SELECT * FROM `online` WHERE `ua`='".$ua."' AND `ip`='".$ip."'"));
	if(!$online_q){
	mysql_query("INSERT INTO `online` SET `time`='".time()."',`ua`='".$ua."',`ip`='".$ip."'");
	}else{
	mysql_query("UPDATE `online` SET `time`='".time()."' WHERE `ua`='".$ua."' AND `ip`='".$ip."'");
	}

}


?>