chat.php
Código PHP:
este es el que guardaria el id de cada usuario, el problema lo tengo en el ajax que muestra el chat. Ver original
<?php global $dbh; if ($_GET['action'] == "chatheartbeat") { chatHeartbeat(); } if ($_GET['action'] == "sendchat") { sendChat(); } if ($_GET['action'] == "closechat") { closeChat(); } if ($_GET['action'] == "startchatsession") { startChatSession(); } } } function chatHeartbeat() { $sql = "select * from chat where (chat.to = '".mysql_real_escape_string($_SESSION['logueado_nombre'])."' AND recd = 0) order by id ASC"; $items = ''; $items = $_SESSION['chatHistory'][$chat['from']]; } $chat['message'] = sanitize($chat['message']); $items .= <<<EOD { "s": "0", "f": "{$chat['from']}", "m": "{$chat['message']}" }, EOD; $_SESSION['chatHistory'][$chat['from']] = ''; } $_SESSION['chatHistory'][$chat['from']] .= <<<EOD { "s": "0", "f": "{$chat['from']}", "m": "{$chat['message']}" }, EOD; $_SESSION['openChatBoxes'][$chat['from']] = $chat['sent']; } foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) { $message = "Sent at $time"; if ($now > 180) { $items .= <<<EOD { "s": "2", "f": "$chatbox", "m": "{$message}" }, EOD; $_SESSION['chatHistory'][$chatbox] = ''; } $_SESSION['chatHistory'][$chatbox] .= <<<EOD { "s": "2", "f": "$chatbox", "m": "{$message}" }, EOD; $_SESSION['tsChatBoxes'][$chatbox] = 1; } } } } $sql = "update chat set recd = 1 where chat.to = '".mysql_real_escape_string($_SESSION['logueado_nombre'])."' and recd = 0"; if ($items != '') { } ?> { "items": [ <?php echo $items;?> ] } <?php } function chatBoxSession($chatbox) { $items = ''; $items = $_SESSION['chatHistory'][$chatbox]; } return $items; } function startChatSession() { $items = ''; foreach ($_SESSION['openChatBoxes'] as $chatbox => $void) { $items .= chatBoxSession($chatbox); } } if ($items != '') { } ?> { "username": "<?php echo $_SESSION['logueado_nombre'];?>", "items": [ <?php echo $items;?> ] } <?php } function sendChat() { $from = $_SESSION['logueado_nombre']; $to = $_POST['to']; $message = $_POST['message']; $messagesan = sanitize($message); $_SESSION['chatHistory'][$_POST['to']] = ''; } $_SESSION['chatHistory'][$_POST['to']] .= <<<EOD { "s": "1", "f": "{$to}", "m": "{$messagesan}" }, EOD; $sql = "insert into chat (chat.from,chat.to,message,sent) values ('".mysql_real_escape_string($from)."', '".mysql_real_escape_string($to)."','".mysql_real_escape_string($message)."',NOW())"; echo "1"; } function closeChat() { echo "1"; } function sanitize($text) { return $text; }