示例#1
0
<?php

/**
 * ----------------------------------------------
 * Flame Web-site (PHP/MySQL)
 * Copyright (c) Maksim <<Klym>> Klimenko
 * URL: http://clan-flame.ru
 * ----------------------------------------------
 */
require "blocks/autoload.php";
require "blocks/db.php";
$rawPost = file_get_contents("php://input");
if ($rawPost) {
    $get = 0;
} else {
    $get = 1;
}
$chat = new MiniChat($db);
$chat->getLastMod();
$messages = $chat->getMessages($get);
// Передаем заголовки и JSON пакет данных
header("Content-Type: text/plain; charset=utf-8");
header("Cache-Control: no-store, no-cache");
header("Last-Modified: " . $chat->lastMod);
echo json_encode($messages);
示例#2
0
文件: addmessage.php 项目: Klym/flame
 * URL: http://clan-flame.ru
 * ----------------------------------------------
 */
session_start();
require "blocks/autoload.php";
require "blocks/db.php";
require "blocks/user.php";
// Читаем данные, переданные в POST
$rawPost = file_get_contents("php://input");
// Заголовки ответа
header("Content-Type: text/plain; charset=utf-8");
header("Cache-Control: no-store, no-cache");
header("Expires: " . date('r', time() - 60 * 60));
// Если данные были переданы...
if ($rawPost) {
    //Разбор пакета JSON
    $data = json_decode($rawPost);
    $text = Comment::checkData($data->text);
    if (empty($text)) {
        echo json_encode(array('result' => 'No data'));
    } else {
        $date = time() - 60 * 60;
        $chat = new MiniChat($db, null, $user->id, $text, $date, $date);
        $chat->insertMessage();
        $message = $chat->generateNewMessage();
    }
    echo json_encode($message);
} else {
    // Данные не переданы
    echo json_encode(array('result' => 'No data'));
}