Вход Регистрация
Файл: chat/index.php
Строк: 111
<?php
require_once('functions/fns.php');

// Выход из чата
if (isset($_GET['logout']))
{
    unset(
$_SESSION['name']);
    
header("Location: ".$_SERVER['PHP_SELF']);
    exit();
}

// Авторизация
if (!isset($_SESSION['name']))
{
    if (isset(
$_POST['name']))
    {
        if (
$_POST['name']!="")
        {
            
$_SESSION['name'] = safe_var($_POST['name']);
        }
        
header("Location: ".$_SERVER['PHP_SELF']);
        exit();
    }
?>    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
        Введите имя:
        <input name="name" type="text" />
        <input name="" type="submit" />
    </form>
<?php    
    
exit();
}
else
{
    
$name $_SESSION['name'];
    
    
// загрузка имеющихся сообщений
    
$sel_result mysql_query("SELECT * FROM chat_logs ORDER BY message_date ASC, id ASC");
    if (
mysql_num_rows($sel_result)>0
    {
        
$sel_row mysql_fetch_array($sel_result);
        do 
        {
            if (
$sel_row['nickname'] == $name// собственное сообщение
            
{
                
$message_code .= '<p class="chat_post_my"><span class="chat_mess_time"><strong>['.date("H:i:s",strtotime($sel_row['message_date'])).']</strong> - </span><span class="chat_nickname">'.$sel_row['nickname'].': </span>'.$sel_row['message_text'].'</p>';
            }
            else 
// чужое сообщение
            
{
                
$message_code .= '<p class="chat_post_other"><span class="chat_mess_time"><strong>['.date("H:i:s",strtotime($sel_row['message_date'])).']</strong> - </span><span class="chat_nickname">'.$sel_row['nickname'].': </span>'.$sel_row['message_text'].'</p>';
            }
            
$last_act $sel_row['id']; // номер текущего последнего сообщения
        
}
        while(
$sel_row mysql_fetch_array($sel_result));
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax чат</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="js/chat_scripts.js"></script>

<style>

#chat_body 
{
    width:800px;
    margin:8px auto 3px;
    float:left;
}
#chat_text_field 

    overflow:auto;
    border:1px solid #999;
    -webkit-border-radius: 5px 5px 5px 5px;
    -moz-border-radius: 5px 5px 5px 5px;
    border-radius: 5px 5px 5px 5px;
    padding:3px;
    background-color:#CCC;
}
#chat_text_input 

    float:left;
    width:600px;
    margin:3px 0;
    font:13px Verdana, Geneva, sans-serif;
    border:1px solid #999;
    -webkit-border-radius: 5px 5px 5px 5px;
    -moz-border-radius: 5px 5px 5px 5px;
    border-radius: 5px 5px 5px 5px;
    
}
#chat_button
{
    float:left;
    margin:2px 5px 2px 15px;
}
#logout_button
{
    float:left;
    margin:2px 5px;
}

.chat_mess_time {font:10px Verdana, Geneva, sans-serif !important; margin:1px 3px;}
.chat_nickname {font-weight:bold;}

.chat_post_my {font:11px Verdana, Geneva, sans-serif !important; margin:1px 3px; color:#161;}
.chat_post_other {font:11px Verdana, Geneva, sans-serif !important; margin:1px 3px; color:#039;}

</style>

</head>
<body>
        
    <div id="chat_body">
    
        <div id="chat_text_field" style="height:300px;">
            <?php echo $message_code?>
        </div>
        
        <input id="last_act" name="last_act" type="hidden" value="<?php echo $last_act?>" /><!--Номер последнего сообщения-->
        <input id="block" name="block" type="hidden" value="no" /><!--Блокировка повторного выполнения функции get_chat_messages()-->
        
        <input id="chat_text_input" name="chat_text_input" type="text" />
        <input id="chat_button" name="chat_button" type="button" value="Ответить"/>
        <input id="logout_button" name="logout_button" type="button" value="Выход" />
         
    </div>

</body>
</html>
Онлайн: 1
Реклама