<?php
/* 
Определяем текущий домен сайта. 
Дальнейшее использование 
echo $set['site'];
*/
$set['site'] = htmlspecialchars($_SERVER['HTTP_HOST']); 
/* 
Записываем в константу полный путь до корня сайта. 
Я обычно использую в функции require_once, т.к при указании полного пути до файла, файл находится быстрее 
*/
define("H", $_SERVER["DOCUMENT_ROOT"].'/');
/*
==========================
Подключение к базе
==========================
*/
ob_start();
$db = mysql_connect('localhost','db1400865068','123456');
mysql_query('SET NAMES`utf8`',$db); 
// Устанавливаем кодировку по умолчанию 
mysql_select_db('db1400865068',$db);
// Загрузка остальных плагинов из папки "core/function/"
$opdirbase = opendir(H.'core/function/');
while ($filebase = readdir($opdirbase))
{
if (preg_match('#\.php$#i', $filebase))
{
require_once(H.'core/function/' . $filebase);
}
}


function smiles($text){
$aa = mysql_query("SELECT name,adres FROM `smiles` order by `id` desc");
while($ba = mysql_fetch_assoc($aa)){
$text=str_replace($ba['name'],'<img src="'.$ba['adres'].'" alt="smile" />', $text);
}
$bbcode = array(
'/\[i\](.+)\[\/i\]/isU' => '<em>$1</em>',
'/\[b\](.+)\[\/b\]/isU' => '<strong>$1</strong>',
'/\[u\](.+)\[\/u\]/isU' => '<span style="text-decoration:underline;">$1</span>',
'/\[big\](.+)\[\/big\]/isU' => '<span style="font-size:large;">$1</span>',
'/\[center\](.+)\[\/center\]/isU' => '<center>$1</center>',
'/\[small\](.+)\[\/small\]/isU' => '<span style="font-size:xx-small;">$1</span>',
'/\[red\](.+)\[\/red\]/isU' => '<span style="color:#ff0000;">$1</span>',
'/\[green\](.+)\[\/green\]/isU' => '<span style="color:#00bb00;">$1</span>',
'/\[blue\](.+)\[\/blue\]/isU' => '<span style="color:#0000bb;">$1</span>',
'/\[white\](.+)\[\/white\]/isU' => '<span style="color:#ffffff;">$1</span>');

$text= preg_replace(array_keys($bbcode), array_values($bbcode), $text);
$text = preg_replace('/\[img\]{1}(.+?)\[\/img\]{1}/', '<img src="$1"/>', $text);


return nl2br($text);
}
/*
========================
Куки
========================
*/
session_start();

if(mysql_result(mysql_query("SELECT count(id) from `ipban` where `ip` = '".check($_SERVER['REMOTE_ADDR'])."'"),0) >= 1){
echo'Ваш IP заблокирован.'; exit;
}

if(isset($_COOKIE['nick'])  && isset($_COOKIE['pass'])) {
$usernick = check($_COOKIE['nick']);
$userpass = check($_COOKIE['pass']);
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `nick` =
'$usernick' && `pass` = '$userpass' LIMIT
1"));
} 
// Дальнейшее обращение к пользователю $user['nick']
$act = isset($_GET['act']) ? htmlspecialchars($_GET['act']) : '';
// Постраничная навигация
if ($user['set_p_str']!=NULL)
$set['p_str'] = $user['set_p_str'];
mysql_query("update `user` set `online` = '".time()."', `ip` = '".htmlspecialchars(mysql_real_escape_string($_SERVER['REMOTE_ADDR']))."' where  (`id` = '".$user['id']."') LIMIT 1");
mysql_query("update `user` set `health` = '".($user['health'] < $user['max_health'] ? ($user['health']+3) : ($user['health']+0) )."' where  (`id` = '".$user['id']."') LIMIT 1");
$param = $user[sila] + $user[lovk] + $user[zashit] + $user[max_health];
mysql_query("UPDATE `user` SET `param` = '$param' WHERE `id` = '$user[id]' LIMIT 1");
if($user[health] < 0)mysql_query("UPDATE `user` SET `health` = '0' WHERE `id` = '$user[id]' LIMIT 1");



function pagenav($base_url, $start, $max_value, $num_per_page) {
    ////////////////////////////////////////////////////////////
    // Функция постраничной навигации                         //
    ////////////////////////////////////////////////////////////
    // За основу взята аналогичная функция от форума SMF2.0   //
    ////////////////////////////////////////////////////////////
    $pgcont = 4;
    $pgcont = (int)($pgcont - ($pgcont % 2)) / 2;
    if ($start >= $max_value)
        $start = max(0, (int)$max_value - (((int)$max_value % (int)$num_per_page) == 0 ? $num_per_page : ((int)$max_value % (int)$num_per_page)));
    else
        $start = max(0, (int)$start - ((int)$start % (int)$num_per_page));
    $base_link = '<a href="' . strtr($base_url, array ('%' => '%%')) . 'starts=%d' . '">%s</a> ';
    $pageindex = $start == 0 ? '' : sprintf($base_link, $start - $num_per_page, '&lt;&lt;');
    if ($start > $num_per_page * $pgcont)
        $pageindex .= sprintf($base_link, 0, '1');
    if ($start > $num_per_page * ($pgcont + 1))
        $pageindex .= '<span style="font-weight: small;"> ... </span>';
    for ($nCont = $pgcont; $nCont >= 1; $nCont--)
        if ($start >= $num_per_page * $nCont) {
            $tmpStart = $start - $num_per_page * $nCont;
            $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
        }
    $pageindex .= '[<b>' . ($start / $num_per_page + 1) . '</b>] ';
    $tmpMaxPages = (int)(($max_value - 1) / $num_per_page) * $num_per_page;
    for ($nCont = 1; $nCont <= $pgcont; $nCont++)
        if ($start + $num_per_page * $nCont <= $tmpMaxPages) {
            $tmpStart = $start + $num_per_page * $nCont;
            $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
        }
    if ($start + $num_per_page * ($pgcont + 1) < $tmpMaxPages)
        $pageindex .= '<span style="font-weight: small;"> ... </span>';
    if ($start + $num_per_page * $pgcont < $tmpMaxPages)
        $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
    if ($start + $num_per_page < $max_value) {
        $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
        $pageindex .= sprintf($base_link, $display_page, '&gt;&gt;');
    }
    return $pageindex;
}

foreach($_GET as $ad){
  if(is_numeric($ad)){
$ad = abs(intval($ad));
}
 if(preg_match('/\include|asc|--|select|union|update|from|where|eval|glob|include|require|script|shell|BENCHMARK|CONCAT|INSERT\b/i', $ad)){

$source = 'USER: '.$_SERVER['REMOTE_ADDR'].' | FILE: '.htmlspecialchars($_SERVER["REQUEST_URI"]).'
';
$file = htmlspecialchars($_SERVER['DOCUMENT_ROOT']).'/logs/log91.txt';
$Saved_File = fopen($file, 'a+');
fwrite($Saved_File, $source);
fclose($Saved_File);

header("Refresh: 2;url=/index.php".SID);
 exit('Защита by MrDeath');
 }

 $ad = htmlspecialchars(mysql_real_escape_string($ad));

 }
 foreach($_POST as $ad){
  if(is_numeric($ad)){
$ad = abs(intval($ad));
}else{
 $ad = htmlspecialchars(mysql_real_escape_string($ad));
 }
}
 foreach($_SESSION as $ad){
 $ad = htmlspecialchars(mysql_real_escape_string($ad));
 }
 foreach($_COOKIE as $ad){
 $ad = htmlspecialchars(mysql_real_escape_string($ad));
 }
 $id = isset($_GET['id'])?abs(intval($_GET['id'])):NULL;

?>