View file sys/inc/mysql.php

File size: 2.63Kb
<?php
#--хост--#
$sql['host'] = "localhost";
#--пользователь--#
$sql['user'] = "root";
#--пароль--#
$sql['pass'] = "";
#--имя--#
$sql['base'] = "test1";
#---#
if(!($db=mysql_connect($sql['host'], $sql['user'], $sql['pass']))) die("Не могу подключиться к MySQL серверу!");
if (!mysql_select_db($sql['base'])) die("Не могу подключиться к Базе Даных!");
mysql_query('set charset utf8',$db);
mysql_query('SET names utf8',$db);
mysql_query('set character_set_client="utf8"',$db);
mysql_query('set character_set_connection="utf8"',$db);
mysql_query('set character_set_result="utf8"',$db);
$SET = mysql_fetch_assoc(mysql_query("SELECT * FROM `set`"));
$ip=false;
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']!='127.0.0.1' && preg_match("#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#",$_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip2['xff']=$_SERVER['HTTP_X_FORWARDED_FOR'];
$ipa[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if(isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP']!='127.0.0.1' && preg_match("#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#",$_SERVER['HTTP_CLIENT_IP']))
{
$ip2['cl']=$_SERVER['HTTP_CLIENT_IP'];
$ipa[] = $_SERVER['HTTP_CLIENT_IP'];
}
if(isset($_SERVER['REMOTE_ADDR']) && preg_match("#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#",$_SERVER['REMOTE_ADDR']))
{
$ip2['add']=$_SERVER['REMOTE_ADDR'];
$ipa[] = $_SERVER['REMOTE_ADDR'];
}
$ip=$ipa[0];
$iplong =ip2long($ip);

if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) {
$ua = htmlspecialchars(mysql_escape_string(trim($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])));
} elseif(isset($_SERVER['HTTP_USER_AGENT'])) {
$ua = htmlspecialchars(mysql_escape_string(trim($_SERVER['HTTP_USER_AGENT'])));
} else $ua = 'unk';
mysql_query("DELETE FROM `g` WHERE `time` < '".(time()-600)."'");
if ($_SESSION['uid']>0){
$q = mysql_query("SELECT * FROM `user` WHERE `id` = '$_SESSION[uid]' LIMIT 1 ");
	if (mysql_num_rows($q) != 0) {
	$user = mysql_fetch_assoc($q);
	mysql_query("UPDATE `user` SET `sess` = '$sess', `online` = '1', `iplong` = '$iplong', `ua` = '$ua', `time` = '$time' WHERE `id` = '$user[id]'");}
}
else{
$q = mysql_query("SELECT `id` FROM `g` WHERE `sess` = '$sess' OR (`iplong` = '$iplong' AND `ua` = '$ua') ");
	if ( mysql_num_rows($q) > 0) {
	$id = mysql_result($q, 0);
	mysql_query("UPDATE `g` SET `ua` = '$ua', `iplong` = '$iplong', `sess` = '$sess', `time` = '$time' WHERE `id` = '$id' LIMIT 1 " );
	} 
	else mysql_query("INSERT INTO `g` (ua, iplong, sess, time) VALUES ('$ua', '$iplong', '$sess', '$time')");	
}
?>