View file sys/dbconnect.php

File size: 11.03Kb
<?php
	error_reporting(0);
$ini_s=parse_ini_file('config.ini', true);
$db_host = 'localhost';//хост
$user1=$ini_s['main']['sql_user']; //пользователь
$mysql=$ini_s['main']['sql_base']; //бд
$pass=$ini_s['main']['sql_pass']; //пароль
	
	mysql_connect($db_host, $user1, $pass) or die('Нет соединения с сервером');
	mysql_select_db($mysql) or die('Нет соединения с базой данных');
	mysql_query("SET NAMES UTF8");
	
	$config = mysql_fetch_assoc(mysql_query("SELECT * FROM `config` WHERE `id`='1'"));
	///////////////////////////
	if($_SERVER['PHP_SELF']!='reg.php'){
if(isset($_POST['login']) && isset($_POST['pass'])){
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `login` = '".input($_POST['login'])."' AND `pass` = '".md5(md5($_POST['pass']))."' LIMIT 1"), 0) == 1){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `login`='".input($_POST['login'])."' AND `pass`='".md5(md5($_POST['pass']))."' LIMIT 1"));
$_SESSION['id_user'] = $user['id'];
mysql_query("UPDATE `users` SET `date_last` = '". time() ."' WHERE `id` = '$user[id]' LIMIT 1");
if (isset($_POST['auth_save'])) {
setcookie('id_user', $user['id'], time() + 1000000, '/');
setcookie('pass', $_POST['pass'], time() + 1000000, '/');
}
} 
else $err = $err .'Неверный логин или пароль<br />';} 
else if(isset($_SESSION['id_user']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `id`='". intval($_SESSION['id_user']) ."' LIMIT 1"), 0) == 1){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '". intval($_SESSION['id_user']) ."' LIMIT 1"));
mysql_query("UPDATE `users` SET `date_last` = '". time() ."' WHERE `id` = '$user[id]' LIMIT 1");
}elseif(isset($_COOKIE['id_user']) && isset($_COOKIE['pass']) && $_COOKIE['id_user'] != NULL && $_COOKIE['pass'] != NULL){
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `id`='".intval($_COOKIE['id_user'])."' AND `pass`='". md5(md5($_COOKIE['pass']))."' LIMIT 1"),0)==1){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id`='".intval($_COOKIE['id_user'])."' LIMIT 1"));
$_SESSION['id_user'] = $user['id'];
mysql_query("UPDATE `users` SET `date_last`='".time()."' WHERE `id`='$user[id]' LIMIT 1");
}else{
setcookie('id_user', $user['id'], time() + 1000000, '/');
setcookie('pass', $_POST['pass'], time() + 1000000, '/');
}
}
}
////////////////////////////////////////
	define ('HOME', $_SERVER['DOCUMENT_ROOT']);
	$HOME = 'http://'.$_SERVER['HTTP_HOST'].''; //без /	
	/////////////////////////////////////////////ФУНКЦИИ//////////////////////////////////////////////
	//ф-ия рекламы‹
	$cookie_life = "604800";//время жизни кукисов
  $na_stranice = "3";//пунктов голосования  
function ads()
	{
	echo'<div class="ads">';
	$sql = mysql_query("SELECT * FROM `rekl`");
		while($ads = mysql_fetch_array($sql))
			{
			echo'<a href="rekl.php?id='.num($ads['id']).'">'.output($ads['name']).'</a>';
			}		
	echo'</div>';
	}
//ф-ия подсветки php кода
function highlight($php) {
    $php = strtr($php, array('<br />' => '', '\\' => ''));
    $php = html_entity_decode(trim($php), ENT_QUOTES, 'UTF-8');
    $php = substr($php, 0, 2) != "<?" ? $php = "<?php\n" . $php . "\n?>" : $php;
    $php = highlight_string(stripslashes($php), true);
    return $php;
}

//ф-ия бб кодов
function BBcode($str)
	{
		$str = preg_replace("#\[red\](.*?)\[/red\]#si", "<span style=\"color: red\">\\1</span>", $str);
		$str = preg_replace("#\[blue\](.*?)\[/blue\]#si", "<span style=\"color: blue\">\\1</span>", $str);
		$str = preg_replace("#\[black\](.*?)\[/black\]#si", "<span style=\"color: black\">\\1</span>", $str);
		$str = preg_replace("#\[green\](.*?)\[/green\]#si", "<span style=\"color: green\">\\1</span>", $str);
		$str = preg_replace("#\[small\](.*?)\[/small\]#si", "<span style=\"font-size: 8px\">\\1</span>", $str);
		$str = preg_replace("#\[b\](.*?)\[/b\]#si", "<b>\\1</b>", $str);
		$str = preg_replace("#\[u\](.*?)\[/u\]#si", "<u>\\1</u>", $str);
		$str = preg_replace("#\[i\](.*?)\[/i\]#si", "<i>\\1</i>", $str);
		$str = preg_replace("#\[strike\](.*?)\[/strike\]#si", "<strike>\\1</strike>", $str);
		$str = preg_replace( array ('#\[code\](.*?)\[\/code\]#se'), array ("''.highlight('$1').''"), str_replace("]\n", "]", $str));
		return $str;
	}
//ф-ия свободного места на диске
function dirsize($size) 
	{ 
		$kor = $_SERVER['DOCUMENT_ROOT']; 
		$kor = preg_replace('/[A-Z]\:/','',$kor); 
		$size = disk_free_space($kor.$size); 
		if ($size >= 1073741824) { 
		$size = round($size / 1073741824 * 100) / 100 . ' Gb'; 
		} elseif ($size >= 1048576) { 
		$size = round($size / 1048576 * 100) / 100 . ' Mb'; 
		} elseif ($size >= 1024) { 
		$size = round($size / 1024 * 100) / 100 . ' Kb'; 
		} else { 
		$size = $size . ' b'; 
		} 
			return $size; 
	}
	//ф-ия ip
function get_ip() {
	if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		if (is_ip($_SERVER['HTTP_X_FORWARDED_FOR']))
			return $_SERVER['HTTP_X_FORWARDED_FOR'];
		foreach( explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']) as $ip ) {
			$ip=trim($ip);
			if (is_ip($ip))
				return $ip;
		}
	}
	return $_SERVER['REMOTE_ADDR'];
}
// проверить валидность ip адреса
function is_ip($ip) 
{
    return (false===ip2long($ip)) ? false : true;
}
//ф-ия правильного окончания для цифр
function moneys($string) 
{
    $string = (int)$string;
    $str1 = abs($string) % 100;
    $str2 = $string % 10;
    if ($str1 > 10 && $str1 < 20) return $string . ' рублей';
    if ($str2 > 1 && $str2 < 5) return $string . ' рубля';
    if ($str2 == 1) return $string . ' рубль';
    return $string . ' руб';
} 
//ф-ия навигации
function nav($all,$p=1, $go , $page)
	{
		$max = ceil($all/$page);
		if($max>1)
		{
		echo'<div class="login">Страницы: ';
		$in=-4;
		$out=4;
		if($p!=1)
		{
		echo (' <a href="'.$go.'p=1">1</a> ');
		}
		else
		{
		echo ('<b>1</b>');
		}
		for ($ot=$in; $ot<=$out; $ot++)
		{
		$str=$p+$ot;
		if($str>1 AND $str<$max)
		{
		if($in==$ot AND $str>2)
		{
		echo (' [...] ');
		}
		if($ot!=0)
		{
		echo (' <a href="'.$go.'p='.$str.'"> '.$str.' </a>');
		}    
		else
		{
		echo (' <b>'.$str.'</b>');
		}
		if($ot==$out AND $str<$max-1)
		{
		echo (' [...] ');
		}
		}
		}
		if($p!=$max)
		{
		echo (' <a href="'.$go.'p='.$max.'"> '.$max.' </a>');
		}
		elseif($max>1)
		{
		echo ('<b>'.$max.'</b>');
		}
		echo '</div>';
		}
	}
//ф-ия фильтра чисел
function num($var) 
	{
		return abs(intval($var));
	} 
//ф-ия фильтра при выводе
function output($var) 
	{
		return nl2br(htmlspecialchars($var, ENT_QUOTES));
	}
//ф-ия фильтра текста при заносе в бд
function input($var) 
	{
		return mysql_real_escape_string(trim($var));
	}
/* функция определения размера файла или данных */
function size($in)
	{
	if($in>=1073741824){return '<b>'.round($in/1073741824 ,2).'</b> гб';}
	elseif($in>=1048576){return '<b>'.round($in/1048576 ,2).'</b> мб';}
	elseif($in>=1024){return '<b>'.round($in/1024 ,2).'</b> кб';}
	else{return '<b>'.round($in).'</b> байт';}
	}
//ф-ия смайлов
function smile($text)
{
$files=glob('../smiles/*.png');
$smiles=array( );
$pics=array();
	foreach($files as $a_files)
	{
	$name = pathinfo($a_files, PATHINFO_FILENAME );
	$smiles[] = '|\.'.preg_quote($name).'\.|i'; 
	$pics[] = '<img src="'.$a_files.'" alt="'.$name.'">';
	}
return preg_replace( $smiles, $pics, $text );
}
//ф-ия кол-ва символов
function strlens($var) 
	{
$rus = array('й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф','ы','в','а','п','р','о','л','д','ж','э','я','ч','с','м','и','т','ь','б','ю','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф','Ы','В','А','П','Р','О','Л','Д','Ж','Э','Я','Ч','С','М','И','Т','Ь','Б','Ю');
return strlen(str_replace($rus, '0', $var));    
	}
//ф-ия от бб кодов
function un_BBcode($str)
	{
		$str = preg_replace("#\[red\](.*?)\[/red\]#si", "\\1", $str);
		$str = preg_replace("#\[blue\](.*?)\[/blue\]#si", "\\1", $str);
		$str = preg_replace("#\[black\](.*?)\[/black\]#si", "\\1", $str);
		$str = preg_replace("#\[green\](.*?)\[/green\]#si", "\\1", $str);
		$str = preg_replace("#\[small\](.*?)\[/small\]#si", "\\1", $str);
		$str = preg_replace("#\[b\](.*?)\[/b\]#si", "\\1", $str);
		$str = preg_replace("#\[u\](.*?)\[/u\]#si", "\\1", $str);
		$str = preg_replace("#\[i\](.*?)\[/i\]#si", "\\1", $str);
		$str = preg_replace("#\[strike\](.*?)\[/strike\]#si", "\\1", $str);
		$str = preg_replace("#\[code\](.*?)\[/code\]#si", "\\1", $str);
		return $str;
	}
//ф-ия ua
function GetUserAgent() {
$agent = check($_SERVER['HTTP_USER_AGENT']);
if (stripos($agent, 'Avant Browser') !== false) {return 'Avant Browser';} 
elseif (stripos($agent, 'Acoo Browser') !== false) {return 'Acoo Browser';} 
elseif (stripos($agent, 'MyIE2') !== false) {return 'MyIE2';} 
elseif (preg_match('|Iron/([0-9a-z\.]*)|i', $agent, $pocket)) {return 'SRWare Iron ' . subtok($pocket[1], '.', 0, 2);} 
elseif (preg_match('|Chrome/([0-9a-z\.]*)|i', $agent, $pocket)) {return 'Chrome ' . subtok($pocket[1], '.', 0, 3);} 
elseif (preg_match('#(Maxthon|NetCaptor)( [0-9a-z\.]*)?#i', $agent, $pocket)) {return $pocket[1] . $pocket[2];} 
elseif (stripos($agent, 'Safari') !== false && preg_match('|Version/([0-9]{1,2}.[0-9]{1,2})|i', $agent, $pocket)) {return 'Safari ' . subtok($pocket[1], '.', 0, 2);} 
elseif (preg_match('#(NetFront|K-Meleon|Netscape|Galeon|Epiphany|Konqueror|Safari|Opera Mini)/([0-9a-z\.]*)#i', $agent, $pocket)){return $pocket[1] . ' ' . subtok($pocket[2], '.', 0, 2);} 
elseif (stripos($agent, 'Opera') !== false && preg_match('|Version/([0-9]{1,2}.[0-9]{1,2})|i', $agent, $pocket)) {return 'Opera ' . $pocket[1];} 
elseif (preg_match('|Opera[/ ]([0-9a-z\.]*)|i', $agent, $pocket)) {return 'Opera ' . subtok($pocket[1], '.', 0, 2);} 
elseif (preg_match('|Orca/([ 0-9a-z\.]*)|i', $agent, $pocket)) {return 'Orca ' . subtok($pocket[1], '.', 0, 2);} 
elseif (preg_match('#(SeaMonkey|Firefox|GranParadiso|Minefield|Shiretoko)/([0-9a-z\.]*)#i', $agent, $pocket)) {return $pocket[1] . ' ' . subtok($pocket[2], '.', 0, 3);} 
elseif (preg_match('|rv:([0-9a-z\.]*)|i', $agent, $pocket) && strpos($agent, 'Mozilla/') !== false) {return 'Mozilla ' . subtok($pocket[1], '.', 0, 2);} 
elseif (preg_match('|Lynx/([0-9a-z\.]*)|i', $agent, $pocket)) {return 'Lynx ' . subtok($pocket[1], '.', 0, 2);} 
elseif (preg_match('|MSIE ([0-9a-z\.]*)|i', $agent, $pocket)) {return 'IE ' . subtok($pocket[1], '.', 0, 2);} else {
$agent = preg_replace('|http://|i', '', $agent);
$agent = strtok($agent, '( ');
$agent = substr($agent, 0, 22);
$agent = subtok($agent, '.', 0, 2);
if(!empty($agent)){return $agent;} 
return 'Unknown';
} 
}
  

?>