Размер файла: 4.02Kb
<?
header("Content-Type: text/vnd.wap.wml");
print ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
print ("<wml>");
print ("<head><meta http-equiv=\"Cache-Control\" content=\"max-age=30\" forua=\"true\"/></head>");
print ("<card id=\"guest\" title=\"Гостевая книга\">\n");
print ("<p><do name=\"a2\" type=\"options\" label=\"Написать\">\n");
print ("<go href=\"guest.php\"/></do>");
print ("<do name=\"a3\" type=\"options\" label=\"На главную\">\n");
print ("<go href=\"/index.php\"/></do>");
print ("<do name=\"a4\" type=\"options\" label=\"Мыло мне\">\n");
print ("<go href=\"/send/sendmy/send.php\"/></do></p>");
// +-------------------------------+
// | gabir wap GuestBook |
// +-------------------------------+
// | http://gabir.com.ru |
// +-------------------------------+
require("config.php");
function show_form()
{
}
function save_mess()
{
global $name, $email, $mess, $base;
$date = date("d.m.y/H:i");
$text = $name."^^".$email."^^".$date."^^".$mess."\n";
$fp = fopen($base,"a");
fputs($fp, $text);
fclose($fp);
}
function show_mess()
{
global $base, $MessOnScreen;
$file = file($base);
$file = array_reverse($file);
if(sizeof($file) < $MessOnScreen) $MessOnScreen = sizeof($file);
for ($i = 0; $i < $MessOnScreen; $i++)
{
$mess = explode("^^",$file[$i]);
echo "<p><a href='/send/sendto/send.php?to=$mess[1]' title='$mess[0]'>$mess[0]</a>";
echo "<br/>";
echo $mess[2];
echo "<br/>";
echo $mess[3];
echo "</p>";
}
}
function check_mess()
{
global $name, $email, $mess;
$mess=trim($mess);
$email=trim($email);
$name=trim($name);
$name=htmlspecialchars($name);
$email=htmlspecialchars($email);
$mess=htmlspecialchars($mess);
stripslashes($mess); //!!!!!!!!!!!!!!!!!
$mess = str_replace("\n","<br/>",$mess);
check_for_length(); //добавили
if (empty($name)) output_err(2);
if (!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $email)) output_err(1);
if (preg_match("/[^(\w)|(\x7F-\xFF)|(\s)]/",$name)) output_err(2);
check_mess_for_flud(); //добавили
del_mess_from_file(); //добавили
}
function check_for_length()
{
global $mess, $email, $name, $MessLength;
if (strlen($mess)>$MessLength) output_err(3);
$email=substr($email, 0, 21);
$name=substr($name, 0, 22);
}
function check_mess_for_flud()
{
global $mess,$base;
$file=file($base);
$file=implode("",$file);
$mess=preg_quote($mess);
if (eregi($mess, $file)) output_err(4);
$mess = stripslashes($mess);
}
function del_mess_from_file()
{
global $base, $MessInFile;
$file = file($base);
$k = 0;
if($MessInFile<sizeof($file))
{
for($i=sizeof($file)-$MessInFile; $i<sizeof($file); $i++)
{
$ResFile[$k]=$file[$i];
$k++;
}
$fp=fopen($base,"w");
for($i=0; $i<sizeof($ResFile); $i++)
{
fputs($fp, $ResFile[$i]);
}
fclose($fp);
}
}
function output_err($num)
{
global $err;
print ("<p align=\"center\"><b>Бля!</b>\n");
echo $err[$num];
echo "</p>";
exit("</card></wml>");
}
if ($mess) {
check_mess();
save_mess();
}
show_mess();
show_form();
print ("</card>");
print ("</wml>");
?>