codigos
index.php   
Código PHP:
Ver original- <?php 
-   
-   
- function loginForm(){ 
- echo 
- '<div id="loginform"> 
- <form action="index.php" method="post"> 
- <p>Please enter your name to continue:</p> 
- <label for="name">Name:</label> 
- <input type="text" name="name" id="name" /> 
- <input type="submit" name="enter" id="enter" value="Enter" /> 
- </form> 
- </div>' 
- ; 
- } 
-   
- if(isset($_POST['enter'])){ 
- if($_POST['name'] != ""){ 
- } 
- else{ 
- echo '<span class="error">Please type in a name</span>'; 
- } 
- } 
- //desloguea 
- if(isset($_GET['logout'])){ 
-   
- //Mensaje simple de salida 
- $fp = fopen("log.html", 'a'); 
- fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." has left the chat session.</i><br></div>"); 
-   
- header("Location: index.php"); //Redirige al usuario 
- } 
-   
- //fin desloguea 
- ?> 
-   
-   
-   
- <!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> 
- <title>Chat - Customer Module</title> 
- <link type="text/css" rel="stylesheet" href="style.css" /> 
- </head> 
-   
- <?php 
- if(!isset($_SESSION['name'])){ 
- loginForm(); 
- } 
- else{ 
- ?> 
- <div id="wrapper"> 
- <div id="menu"> 
- <p class="welcome">Welcome, <b><?php echo $_SESSION['name']; ?></b></p> 
- <p class="logout"><a id="exit" href="#">Exit Chat</a></p> 
- <div style="clear:both"></div> 
- </div> 
- <div id="chatbox"><?php 
- $handle = fopen("log.html", "r"); 
-   
- echo $contents; 
- } 
- ?></div> 
- <form name="message" action=""> 
- <input name="usermsg" type="text" id="usermsg" size="63" /> 
- <input name="submitmsg" type="submit"  id="submitmsg" value="Send" /> 
- </form> 
- </div> 
-   
-   
- <script type="text/javascript" src="jquery.min.js"></script> 
- <script type="text/javascript"> 
-   
- $(document).ready(function(){ 
- //Si el usuario quiere dejar la sesión 
- $("#exit").click(function(){ 
- var exit = confirm("¿Está seguro que desea finalizar la sesión?"); 
- if(exit==true){window.location = 'index.php?logout=true';} 
- }); 
- //enviar en log de mensaje 
- $("#submitmsg").click(function(){ 
- var clientmsg = $("#usermsg").val(); 
- $.post("post.php", {text: clientmsg}); 
- $("#usermsg").attr("value", ""); 
- return false; 
- }); 
- //Carga el archivo que contiene el log de chat 
- function loadLog(){//Inicio de loadLog 
- var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //La altura del scroll antes de la petición 
- $.ajax({//Inicio ajax 
- url: "log.html", 
- cache: true, 
- success: function(html){//Inicio del success 
- $("#chatbox").html(html); //Inserta el log de chat en el div #chatbox 
- //Auto-scroll 
- var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; //La altura del scroll después del pedido 
- if(newscrollHeight > oldscrollHeight){//inicio del if verificar scroll 
- $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll hacia el fondo del div 
- }//Fin del if verificar scroll 
- }//Fin del success 
- });//Fin ajax 
- }//Fin de loadLog 
- //Recarga el archivo cada 2500 ms o x ms si deseas cambiar el segundo parámetro 
- setInterval (loadLog, 2500); 
- });//fin del Jquery 
-   
-   
- </script> 
- <?php 
- } 
- ?> 
-   
-   
-   
-   
-   
- </body> 
- </html> 
post.php   
Código PHP:
Ver original- <? 
- if(isset($_SESSION['name'])){ 
- $text = $_POST["text"]; 
-   
- $fp = fopen("log.html", 'a'); 
- } 
- ?> 
style.css    
Código CSS:
Ver original- @charset "utf-8"; 
- /* CSS Document */ 
- /* CSS Document */ 
- body { 
- font:12px arial; 
- color: #222; 
- text-align:center; 
- padding:35px; } 
-   
- form, p, span { 
- margin:0; 
- padding:0; } 
-   
- input { font:12px arial; } 
-   
- a { 
- color:#0000FF; 
- text-decoration:none; } 
-   
- a:hover { text-decoration:underline; } 
-   
- #wrapper, #loginform { 
- margin:0 auto; 
- padding-bottom:25px; 
- background:#EBF4FB; 
- width:504px; 
- border:1px solid #ACD8F0; } 
-   
- #loginform { padding-top:18px; } 
-   
- #loginform p { margin: 5px; } 
-   
- #chatbox { 
- text-align:left; 
- margin:0 auto; 
- margin-bottom:25px; 
- padding:10px; 
- background:#fff; 
- height:270px; 
- width:430px; 
- border:1px solid #ACD8F0; 
- overflow:auto; } 
-   
- #usermsg { 
- width:395px; 
- border:1px solid #ACD8F0; } 
-   
- #submit { width: 60px; } 
-   
- .error { color: #ff0000; } 
-   
- #menu { padding:12.5px 25px 12.5px 25px; } 
-   
- .welcome { float:left; } 
-   
- .logout { float:right; } 
-   
- .msgln { margin:0 0 2px 0; }