Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/06/2008, 15:17
Avatar de pateketrueke
pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años, 1 mes
Puntos: 2534
Respuesta: como hago un 'Chatbox'

para Ajax hay bastantes librerias.... yo uso jQuery

también te hice esto, es rápido... pero espero que te sirva para entender como funciona un simple.... shoutbox o chat chiquito....

Código PHP:
<?php
    $chat_file 
// formato tipo: chat-10-06-1987.txt
        
'chat-'.date('d-m-Y').'.txt';
    if (!
is_file($chat_file))
    {
        
// creamos el archivo?
        
touch($chat_file);
    }
    
    
    
// ahora, a leer los mensajes...
    
    
$mensajes file($chat_file);
    
    if (isset(
$_POST['texto']) &&
            isset(
$_POST['nick'])) // obligatorios!
    
{
        
$autor $_POST['nick'];
        
        
// creamos una cookie para el nick del autor...
        
setcookie('nick'$autortime() + 84000);
        
        
$mensaje $_POST['texto'];
        
$mensaje strip_tags($mensaje);
        
$mensaje htmlentities($mensaje);
        
        
$mensajes[] = "$autor <b>dijo:</b> $mensaje\n"// agregamos
        
        
        // reescribimos el archivo...
        
$tmp fopen($chat_file'w+');
        
fwrite($tmpjoin(''$mensajes));
        
fclose($tmp);
        
        
        
// regresamos!!!!
        
header('location: '.$_SERVER['REQUEST_URI']);
    }
?>
<!--- aqui va el HTML -->
<div id="mensajes"><?php
    
    
foreach ($mensajes as $linea)
    {
        echo 
'<span class="mensaje" style="display: block">'.$linea.'</span>';
    }
    
    
    
// restauramos la cookie del autor???
    
$autor = isset($_COOKIE['nick'])? $_COOKIE['nick']: '';

?></div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <div>
        <input type="text" size="13" name="nick" value="<?php echo $autor?>"/>
        <input type="text" size="52" name="texto"/>
        <input type="submit" value="Enviar"/>
    </div>
</form>
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.