File size: 3.22Kb
<?
function title($title)
{
header("Content-type: application/xhtml+xml; charset=utf-8");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Cache-Control: max-age=0");
header("Pragma: no-cache");
return '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>'.$title.'</title>
<link href="img/style.css" rel="stylesheet" type="text/css" />
</head>
<body>';
}
function the_end()
{
return '<div align="center"><b>(c) by DikS.</b></div></body></html>';
}
function error($error)
{
$content = title('error!').'<div>'.htmlspecialchars($error).'</div>'.the_end();
die($content);
}
function autorize($id,$ps)
{
if(mysql_num_rows(mysql_query('SELECT `id` FROM `books` WHERE `id` = '.(int)$id.' and `password` = MD5("'.mysql_escape_string($ps).'");')) == 1) return (boolean)TRUE;
else return (boolean)FALSE;
}
function get_config($id)
{
$row = mysql_fetch_array(mysql_query('SELECT * FROM `books` WHERE `id` = '.$id.';'));
return $row;
}
function GB_codes($str)
{
global $id;
$str = preg_replace('~\[b\]+(.*)\[/b\]+~iSu','<b>\\1</b>',$str); // [b][/b] = <b></b>
$str = preg_replace('~\[u\]+(.*)\[/u\]+~iSu','<u>\\1</u>',$str); // [u][/u] = <u></u>
$str = preg_replace('~\[i\]+(.*)\[/i\]+~iSu','<i>\\1</i>',$str); // [i][/i] = <i></i>
$str = preg_replace('~\[quote\]+(.*)\[/quote\]+~iSu','<b>Цитата:</b><br /><small>\\1</small><hr />',$str); // [quote][/quote] = <b>Цитата:</b><br /><small></small><hr />
$str = preg_replace('~\[url\]+(.*)\[/url\]+~iSu','<a href="gb.php?id='.$id.'&do=url&link=\\1">\\1</a>',$str); // [url][/url] = <a href=""></a><br />
return $str;
}
function no_access()
{
global $id;
if($id != 1)
{
error('No Access!');
}
}
function write_log()
{
if(!is_writable('./security_log.txt'))
{
die('error: in journal of safety not possible to add new record, beforehand not it is enough rights.');
}
$ip = $_SERVER['REMOTE_ADDR'];
$ua = trim($_SERVER['HTTP_USER_AGENT']);
if(round(filesize('./security_log.txt')/1024) > 1024) $root = 'w+';
else $root = 'a+';
$fp = fopen('./security_log.txt',$root);
fputs($fp,'Новая запись.'."\n");
fputs($fp,'Дата: '.date('d/m/Y H:i:s')."\n");
fputs($fp,'IP: '.$ip."\n");
fputs($fp,'Host: '.trim(gethostbyaddr($ip))."\n");
fputs($fp,'UA: '.$ua."\n");
fputs($fp,'Замечен: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.trim($_SERVER['QUERY_STRING'])."\n");
fputs($fp,'Переданные заголовки броузера:'."\n".'Поддержка расширений: '.trim($_SERVER['HTTP_ACCEPT'])."\n".'Язык: '.trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])."\n");
fputs($fp,'Encoding: '.trim($_SERVER['HTTP_ACCEPT_ENCODING'])."\n");
fputs($fp,'Кодировки: '.trim($_SERVER['HTTP_ACCEPT_CHARSET'])."\n");
fputs($fp,'-----------------------------------'."\n");
fclose($fp);
}
?>