File size: 4.47Kb
<?
session_start();
if(isset($_SESSION['chat_name'])){if(trim($_SESSION['chat_name'])!=""){$chat_log=trim(htmlspecialchars($_SESSION['chat_name']));}}
if(isset($_POST['chat_nik'])){if(trim($_POST['chat_nik'])!=""){$chat_nikk=trim(htmlspecialchars($_POST['chat_nik']));}}
//
if(isset($_GET['chat_reg']) and isset($chat_log))
{
?>
Пароль:<input type="password" size="50" maxlength="15" id="chat_passreg"/>
<button onClick="chat_registr()">Регистрировать</button>
<?
exit;
}
if(isset($_GET['chat_registr']) and trim($_POST['chat_passreg'])!='')
{
$chat_password=md5($_POST['chat_passreg']);
$chat_data = date("H:i d.m.Y", time()+3600);
$chat_file = fopen("../data/chat_log.dat", "a+");
$chat_str = "$chat_log::$chat_password::$chat_data\r\n";
flock($chat_file, LOCK_EX);
fwrite($chat_file, $chat_str);
flock($chat_file, LOCK_UN);
fclose($chat_file);
$_SESSION['chat_pass'] = $chat_password;
$chat_login="Ч@Т";
$chat_text="$chat_log теперь зарегистрированый пользователь поздравляем его .smile. ";
$chat_data = date("H:i d.m.Y", time()+3600);
$chat_file = fopen("../data/chat_base.dat", "a+");
$chat_str = "$chat_login::$chat_text::$chat_data\r\n";
flock($chat_file, LOCK_EX);
fwrite($chat_file, $chat_str);
flock($chat_file, LOCK_UN);
fclose($chat_file);
echo'Поздравляем теперь вы зарегистрированый пользователь в нашем чате<br/>
а значит и на радио, не забудти ваш пароль '.htmlspecialchars($_POST['chat_passreg']).' и ник '.$chat_log.'<br/>
<a href="javascript:chat_chat()">перейти к вводу сообщений</a><br/>';
exit;
}
if(isset($_POST['chat_pass'])){$chat_pass = md5($_POST['chat_pass']);}
$chat_log_file=file("../data/chat_log.dat");
$chat_cc=count($chat_log_file);
for($chat_i=0; $chat_i<$chat_cc; $chat_i++)
{
$chat_ex=explode("::", $chat_log_file[$chat_i]);
if(isset($chat_nikk))
{
if(($chat_nikk == $chat_ex[0]) and !isset($chat_pass) and !isset($_SESSION['chat_pass']))
{
$_SESSION['chat_name']=$chat_nikk;
?>
Пароль:<input type="password" size="50" maxlength="15" id="chat_pass"/>
<button onClick="chat_chatpass()">Войти</button>
<?
exit;
}
}
if(isset($_SESSION['chat_name'])){
if(($_SESSION['chat_name'] == $chat_ex[0]) and isset($chat_pass))
{
if($chat_pass == $chat_ex[1]){$_SESSION['chat_pass'] = $chat_pass;}else{unset($_SESSION['chat_name']);}
}
if(($_SESSION['chat_name'] == $chat_ex[0]) and isset($_SESSION['chat_pass']))
{
if($_SESSION['chat_pass'] != $chat_ex[1]){unset($_SESSION['chat_name']); unset($_SESSION['chat_pass']);}
}
if(($_SESSION['chat_name'] == $chat_ex[0]) and !isset($_SESSION['chat_pass'])){unset($_SESSION['chat_name']); unset($_SESSION['chat_pass']);}
}
}
if(isset($chat_nikk))
{
$chat_fail=file("../data/chat_aut.dat");
$chat_c=count($chat_fail);
for($chat_i=0; $chat_i<$chat_c; $chat_i++)
{
$chat_ex=explode("::", $chat_fail[$chat_chat_i]);
if(($chat_nikk == $chat_ex[0]) and ((time()-$chat_ex[1]) < 3600))
{
$chat_nik=true;
echo'Данный Ник занят<br/>';
}
}
}
if(!isset($chat_nik) and isset($chat_nikk))
{
if(strlen($chat_nikk)>15){echo"Ник привышает 15 символов!";}
else
{
$_SESSION['chat_name']=$chat_nikk;
$chat_login="Ч@Т";
$chat_text="К нам присоединяется \"$chat_nikk\", встречаем .smile. ";
$chat_data = date("H:i d.m.Y", time()+3600);
$chat_file = fopen("../data/chat_base.dat", "a+");
$chat_str = "$chat_login::$chat_text::$chat_data\r\n";
flock($chat_file, LOCK_EX);
fwrite($chat_file, $chat_str);
flock($chat_file, LOCK_UN);
fclose($chat_file);
}
}
if(!isset($_SESSION['chat_name']))
{
?>
Ник:<input size="30" maxlength="15" id="chat_log"/>
<button onClick="chat_addchat()">Войти</button>
<?
}
else
{
?>
<?=$_SESSION['chat_name']?><br/>
<?if(!isset($_SESSION['chat_pass'])){?>
<a href="javascript:chat_reg()">Регистрировать данный ник</a><br/>
<?}?>
<div id="chat_soob"></div>
Текст:<br/>
<input id="chat_text" size="70" maxlength="500"><br/>
<button onClick="chat_addchat1()">Добавить</button><br/>
<?
}
?>