<?
// Данные от базы данных

$db_host='localhost'; // хост
$db_password='dadada'; // пароль
$db_user_name='ferma'; // имя пользователя
$db_name='ferma'; // имя базы данных

if(!($db=@mysql_connect($db_host, $db_user_name, $db_password)))
{
echo "<center>Bad MySQL host</center>";
exit;
}

// подключение к базе
if (!@mysql_select_db($db_name,$db))
{
echo "Wrong MySQL db name";
exit;
}
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);
if(empty($_COOKIE['pass']))$_COOKIE['pass']='';
if(!isset($_SESSION))
{
session_name('SESS');
session_start();
$sess=mysql_escape_string(session_id());
if (!preg_match('#[A-z0-9]{32}#i',$sess))$sess=md5(rand(09009,999999));}
if (isset($_SESSION['id_user']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '$_SESSION[id_user]' LIMIT 1"), 0)==1)
{
$ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$_SESSION[id_user]'"));
$conf=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_setting` WHERE `id_user` = '$_SESSION[id_user]'"));
}elseif (isset ($_COOKIE['log_id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `id` = '".(base64_decode($_COOKIE['log_id']))."' AND `password`='".(base64_decode($_COOKIE['pass']))."' LIMIT 1"), 0)==1)
{
$_SESSION['id_user'] = base64_decode($_COOKIE['log_id']);
$_SESSION['pass'] = base64_decode($_COOKIE['pass']);
$ku=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '$_SESSION[id_user]' AND `password`='$_SESSION[pass]'"));
$conf=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_setting` WHERE `id_user` = '$_SESSION[id_user]'"));
}
$set=array();
$set['p_str']=10;

?>