Foros del Web » Programando para Internet » PHP »

Problema con chat en ajax y PHP

Estas en el tema de Problema con chat en ajax y PHP en el foro de PHP en Foros del Web. Cogí los códigos del link: http://www.forosdelweb.com/f127/aporte-crear-chat-con-php-ajax-con-salas-muestra-usuarios-online-651920/ Y me metí a editarlo a fondo, y ahora no funciona, me sale en blanco :S Archivos: Código PHP: ...
  #1 (permalink)  
Antiguo 27/06/2012, 15:13
 
Fecha de Ingreso: abril-2012
Mensajes: 11
Antigüedad: 12 años
Puntos: 0
Exclamación Problema con chat en ajax y PHP

Cogí los códigos del link: http://www.forosdelweb.com/f127/aporte-crear-chat-con-php-ajax-con-salas-muestra-usuarios-online-651920/

Y me metí a editarlo a fondo, y ahora no funciona, me sale en blanco :S

Archivos:
Código PHP:
<?php
session_start
();
$nick=$_SESSION['username']; 
$log=$_SESSION['logged'];
$pre=$_GET['name']; 
?>
    <?php
    session_start
();
    
$nick=$_SESSION['username']; 
    
$log=$_SESSION['logged'];
    
$pre=$_GET['nombre']; 
    if(
$log=="yes"){ 
    
$sala=$_GET['name']; 
    include(
'config.php'); 
    
$user=addslashes($nick); 
    
$n=@mysql_num_rows(mysql_query("SELECT * FROM '\'$pre\''_online WHERE user='".$user."'")); 
    
$qry=@mysql_fetch_array(mysql_query("SELECT * FROM '\'$pre\''_online WHERE user='".$nick."'"));
    
$tiempo=$qry['desban'];
    
$actual=date("H:i:s");
    
$fin=$actual-$tiempo;
    if(
$fin<0){
    if(
$n==0){ 
    
$campos=array('time','user','sala'); 
    
$datos=array(  (time())+$seg_inac,$user,$sala); 
    
$c=implode(',',$campos); 
    
$d='\''.implode("','",$datos).'\''
    
$sSQL=sprintf("INSERT INTO %s (%s) VALUES (%s)","'\'$pre\''_online",$c,$d); 
    
$query mysql_query($sSQL); 
    }else{ 
    
$key=""
    for(
$i=0;$i<=10;$i++) 
    
$key.=rand(0,9); 
    
$user=$user."(".$key.")"
    
$nn=mysql_num_rows(mysql_query("SELECT * FROM '\'$pre\''_online WHERE user='".$user."'")); 
    if(
$nn==0){ 
    
$campos=array('time','user','sala'); 
    
$datos=array(  (time())+$seg_inac,$user,$sala); 
    
$c=implode(',',$campos); 
    
$d='\''.implode("','",$datos).'\''
    
$sSQL=sprintf("INSERT INTO %s (%s) VALUES (%s)","'\'$pre\''_online",$c,$d); 
    
$query mysql_query($sSQL); 
    }else{ 
    die(
"El nick ya existe."); 
    } 
    } 
    
?> 
    <script type="text/javascript"> 
    <!-- 
    var segundos=3; 
    var user="<?php stripslashes($user)?>"; 
    var sala="<?php echo $sala ?>"; 
    var acSegMill=(segundos==0 || segundos>10)? 1000 : segundos*1000; 
    --> 
    </script> 
    <script type="text/javascript" src="chat.js"></script> 
    <?php
    
/************************************************
     * Se empieza el JS para ocultar / mostrar divs *
     ************************************************/
    
?>
    <script type="text/javascript">
            function mostrar_y_ocultar(id,valor)
            {
                document.getElementById("actions").style.display="none";
                document.getElementById("vacio").style.display="none";
                document.getElementById(id).style.display=valor;
            }
    </script>
    <style type="text/css"> 
    <!-- 
    #coment_tr { 
        background-color: #FFFFFF; 
        border-top-width: 2px; 
        border-right-width: 1px; 
        border-bottom-width: 1px; 
        border-left-width: 2px; 
        border-top-style: solid; 
        border-right-style: solid; 
        border-bottom-style: solid; 
        border-left-style: solid; 
        border-top-color: #000000; 
        border-right-color: #666666; 
        border-bottom-color: #666666; 
        border-left-color: #000000; 
        padding: 3px; 
        height: 198px; 
        width: auto; 
        display: block; 
        overflow: auto; 
    } 
    .date_envi { 
        background-color: #EEEEEE; 
        margin-top: 3px; 
        margin-right: 3px; 
        margin-bottom: 1px; 
        margin-left: 3px; 
        padding-top: 3px; 
        padding-right: 3px; 
        padding-bottom: 1px; 
        padding-left: 3px; 
        border-right-width: 1px; 
        border-bottom-width: 1px; 
        border-left-width: 1px; 
        border-right-style: solid; 
        border-bottom-style: solid; 
        border-left-style: solid; 
        border-right-color: #000000; 
        border-bottom-color: #000000; 
        border-left-color: #000000; 
    } 
    .botom { 
        color: #000000; 
        background-color: #FFFFFF; 
        border: 1px solid #999999; 
        height: 20px; 
        width: 100px; 
    } 
    .tabs { 
        background-color: #FFFFFF; 
        float: left; 
        height: auto; 
        width: 98px; 
        display: block; 
        cursor: pointer; 
        text-align: center; 
        padding-bottom: 4px; 
        margin-bottom: 4px; 
    } 
    .tabs_ac { 
        background-color: #E4E5E5; 
        float: left; 
        height: auto; 
        width: 98px; 
        display: block; 
        cursor: pointer; 
        text-align: center; 
        text-decoration: underline; 
        background-position: top; 
        margin-bottom: 4px; 
        padding-bottom: 4px; 
    } 
    #mensaje { 
        background-color: #FFFFFF; 
        padding: 5px; 
        border: 1px solid #000000; 
    } 
    #config { 
        color: #000000; 
        background-color: #EEEEEE; 
        margin: 1px; 
        padding: 1px; 
        height: auto; 
        width: 100px; 
        border: 1px solid #000000; 
        position: relative; 
        visibility: hidden; 
    } 
    .sala { 
        color: #000000; 
        background-color: #EEEEEE; 
        height: auto; 
        width: auto; 
        cursor: pointer; 
        display: block; 
        margin-right: 2px; 
        padding-right: 3px; 
        text-align: center; 
        margin-bottom: 2px; 
        padding-top: 2px; 
        padding-bottom: 2px; 
    } 
    .sala_ac { 
        color: #000000; 
        background-color: #F3F3F3; 
        height: auto; 
        width: auto; 
        cursor: pointer; 
        display: block; 
        margin-right: 2px; 
        padding-right: 3px; 
        text-align: center; 
        margin-bottom: 2px; 
        padding-top: 2px; 
        padding-bottom: 2px; 
        font-weight: bold; 
    } 
    .table { 
        border: 1px solid #000000; 
    } 
    #usuarios { 
        overflow: auto; 
        height: 270px; 
        width: auto; 
    } 
    .cargando { 
        background-color: #FF0000; 
        height: auto; 
        width: 100px; 
        position: absolute; 
        left: 0px; 
        top: 0px; 
        clip: rect(0px,auto,auto,0px); 
        visibility: visible; 
        padding-right: 3px; 
        padding-top: 2px; 
        padding-bottom: 4px; 
        padding-left: 5px; 
    } 
    #bbcode { 
        position:relative; 
        border: thin solid #333333; 
        background-color: #EEEEEE; 
        visibility: hidden; 
        margin: 1px; 
        padding: 1px; 
        height: auto; 
        width: 100px; 
    } 
    --> 
    </style> 
    <div class="cargando" id="cargando"><strong>Cargando...</strong></div> 
    <div id="box" style="visibility:hidden;"> 
    <table width="611" id="chat-tr-ct" border="0" align="center" cellpadding="0" cellspacing="0" class="table"> 
      <tr> 
        <td width="410" height="198" valign="top"><div id="coment_tr">&nbsp;Presione conectar para entrar al chat. </div></td> 
        <td width="492" rowspan="2" valign="top"> 
        <table border="0" cellpadding="0" cellspacing="0"> 
        <tr> 
        <td> 
        <div class="tabs_ac" id="users">Usuarios</div> 
        <div class="tabs" id="salas">Salas</div> 
        </td> 
        </tr> 
        <tr> 
        <td> 
        <div id="usuarios" style="display:block;"></div> 
    
    <div id="sala" style="visibility:; display:none; overflow:auto; height:270px;"> 
    <div class="sala_ac" sala="<?php echo $sala?>"><?php echo $sala?></div> 
    </div> 
        </td> 
        </tr> 
        </table> 
        </td> 
      </tr> 
      <tr> 
        <td bgcolor="#CCCCCC" class="date_envi"><div align="center"> 
          <textarea name="mensaje" cols="50" rows="4" disabled="disabled" id="mensaje" style="width:400px;"  tabindex="1" onkeypress="return envAUT(event);"></textarea>
          <br /> 
          <input name="enviar" onClick="enviarGET($('mensaje'));" type="button" class="botom" id="enviar" value="Enviar" disabled="disabled"> 
           <input name="icono" type="button" class="botom" onClick="verGET('bbcode');" id="icono" value="BBcode">  
           <input name="conf" type="button" class="botom" onClick="verGET('config');" id="conf" value="Configurar">  
           <input name="conection" onClick="conectarGET(this);" type="button" class="botom" id="conection" value="Conectar"> 
           <input name="conection2" onclick="http://arcgame.es" type="button" class="botom" id="conection2" value="ArcGame.es" />
           <input name="conection3" onclick="javascript:mostrar_y_ocultar('default','block');" type="button" class="botom" id="conection3" value="Usuarios" />
           <input name="actions" onclick="javascript:mostrar_y_ocultar('actions','block');" type="button" class="botom" id="actions" value="Acciones" />
           <br /> 
    <font id="nik"><strong>Nick: <?php echo $nick?></strong></font> | <strong>Sala: </strong> <font id="salaET"><?php echo $sala?></font><div id="result"></div> 
        </div></td> 
      </tr> 
    </table> 
    <div style="position:absolute; left:81px; top:276px;"> 
    <div id="config"><div style="background-color:#CCCCCC">Configurar</div> 
      Actualizar cada:  
      <br /> 
      <select name="seg_act" onchange="actualizarTime(this.value);"> 
        <option value="1">1 segundo</option> 
        <option value="2">2 segundo</option> 
        <option value="3">3 segundo</option> 
        <option value="4">4 segundo</option> 
        <option value="5">5 segundo</option> 
        <option value="6">6 segundo</option> 
        <option value="7">7 segundo</option> 
        <option value="8">8 segundo</option> 
        <option value="9">9 segundo</option> 
      </select> 
      <br /> 
      <input name="cerrar-c" type="button" class="botom" id="cerrar-c" onclick="cerrarGET('config');" value=" - Cerrar -" /> 
    </div> 
    </div> 
    <div style="position:absolute; left:81px; top:8px;"> 
    <div align="center" id="bbcode"> 
        <div style="background-color:#CCCCCC;">BBcode</div> 
      <div id="menu-td-edit"> 
      <a href="javascript:b();"><strong>B</strong></a> 
      <a href="javascript:it();"><i>I</i></a> 
      <a href="javascript:u();"><u>U</u></a> 
      <br /> 
      <a href="javascript:colo();">Color</a> 
      <a href="javascript:imagen();">Imagen</a> 
      <a href="javascript:escribir_web();">URL</a> 
      </div> 
        <input name="cerrar" type="button" class="botom" id="cerrar" onclick="cerrarGET('bbcode');" value=" - Cerrar -" /> 
    </div> 
    </div> 
    </div> 
        <div id="actions" align="center">
                   <iframe scrolling="yes" height="400" width="400" src="accionesusuario.php">Tu explorador no soporta iframes, se te recomienda             actualizarlo a una versión más nueva ;) </iframe>
        </div>
    <?php 
    
}
    
session_start();
    
?> 
    <form name="form1" method="post" action=""> 
      Tu nick: <br> 
      <input name="nick" value="<?php $nick?>" disabled="disabled" type="text" id="nick"> 
      <br> 
      <input type="submit" name="Submit" value="Entrar al chat"> 
    </form>  
    <?php 
    ?>
<?php
}
?>
Continua
  #2 (permalink)  
Antiguo 27/06/2012, 15:13
 
Fecha de Ingreso: abril-2012
Mensajes: 11
Antigüedad: 12 años
Puntos: 0
Respuesta: Problema con chat en ajax y PHP

Inter.php
Código PHP:
<?php 
include('config.php');// Incluimos las configuraciones 
if($log="YES"){ 
if(
$_POST['t']=="user"){ 
$user=array(); 
$in=0
$ac=0
$Sqll mysql_query("SELECT * FROM '$pre'_online WHERE sala='".$sala."'",$con) or die(mysql_error());  
while(
$datmysql_fetch_array($Sqll)){ 
$use=stripslashes($dat['user']); 
$time=$dat['time']; 
if(
abs(time()-$time)<(200+$seg_inac)){ 
if(
$time>time()){ 
$ac++; 
$Slll mysql_query("SELECT * FROM '$pre'_users WHERE username='".$nick."'",$con) or die(mysql_error()); 
$rowmysql_fetch_array($Slll);
$rank=$row['rango']; 
$user[]="<img scr='images/".$rank".png'/><strong>".$use."</strong>"
}else{ 
$in++; 
$user[]='<i>'.$use.'</i>'

}else{ 
if(
$use!=$nick){ 
$consulta "DELETE FROM '$pre'_online WHERE id ='".$dat['id']."'"
$resultado mysql_query($consulta) or die(mysql_error()); 



if(empty(
$user)) 
echo 
"No hay usuarios conectados."
else{ 
$user[]="<hr />Hay ".$ac." usuarios activos y ".$in." inactivos.(".($ac+$in).")"
echo 
implode('<br />',$user); 


}elseif(
$_POST['t']=="conectar"){ 
$name=$nick
$sala=$sala
$n=mysql_num_rows(mysql_query("SELECT * FROM '$pre'_online WHERE user='".$name."'")); 
if(
$n==0){ 
$campos=array('time','user','sala'); 
$datos=array(  (time())+$seg_inac,$name,$sala); 
$c=implode(',',$campos); 
$d='\''.implode("','",$datos).'\''
$sSQL=sprintf("INSERT INTO %s (%s) VALUES (%s)","'$pre'_online",$c,$d); 
$query mysql_query($sSQL); 
}elseif(
$n==1){ 
$consulta "Update '$pre'_online set time='".(time()+$seg_inac)."', sala='".$sala."' WHERE user ='".$name."'"
@
$resultado mysql_query($consulta) or die(mysql_error()); 

}elseif(
$_POST['t']=="desconectar"){ 
$consulta "DELETE FROM '$pre'_online WHERE user ='".$_POST['user']."'"
$resultado mysql_query($consulta) or die(mysql_error()); 
}elseif(
$_POST['t']=="ver"){ 
$post=array(); 
$Sqll = @mysql_query("SELECT * FROM '$pre'_contenido WHERE sala='".$sala."' ORDER BY id ASC",$con) or die(mysql_error());  
while(
$datmysql_fetch_array($Sqll)){ 
$mensaje=stripslashes($dat['cont']); 
$mensaje str_replace("[b]","<b>",$mensaje) ; $mensaje str_replace("[/b]","</b>",$mensaje) ; 
$mensaje str_replace("[img]","<img src=\"",$mensaje) ; $mensaje str_replace("[/img]","\" border=\"0\" onerror=this.onerror='this.src=\'\';'>",$mensaje) ; 
$mensaje preg_replace("/\[color=((#)?[0-9a-z]+)\]/i","<font color=\"\\1\">",$mensaje) ; $mensaje str_replace("[/color]","</font>",$mensaje) ; 
$mensaje preg_replace("/\[color=((#)?[0-9a-z]+)\]/i","<font color=\"\\1\">",$mensaje) ; $mensaje str_replace("[/color]","</font>",$mensaje) ; 
$mensaje preg_replace("/\[url\](www\..+)\[\/url\]/i","<a href=\"http://\\1\" target=\"_blank\">\\1</a>",$mensaje) ; 
$mensaje preg_replace("/\[url\](.+)\[\/url\]/i","<a href=\"\\1\" target=\"_blank\">\\1</a>",$mensaje) ; 
$mensaje preg_replace("/\[url=(www\..+)\](.+)\[\/url\]/i","<a href=\"http://\\1\" target=\"_blank\">\\2</a>",$mensaje) ; 
$mensaje preg_replace("/\[url=(.+)\](.+)\[\/url\]/i","<a href=\"\\1\" target=\"_blank\">\\2</a>",$mensaje) ; 
$mensaje str_replace("[i]","<i>",$mensaje) ; $mensaje str_replace("[/i]","</i>",$mensaje) ; 
$mensaje str_replace("[u]","<u>",$mensaje) ; $mensaje str_replace("[/u]","</u>",$mensaje) ; 
/*********************
 * Links permanentes *
 *********************/
$mensaje str_replace("arcgame","<a href='http://www.arcgame.es/' title='ArcGame'>arcgame</a>",$mensaje) ; 
$mensaje str_replace("cambio","<a href='http://www.arcgame.es/chat/cambio' title='Cambio'>cambio</a>",$mensaje) ; 
/*********************
 * Smiles para todos *
 *********************/
    
$mensaje str_replace(":estaciones:","<embed src='emots/smile.swf' wmode='transparent' width='42' height='50' title=':SMILE:'></embed>",$mensaje) ; 

 
/********************
 * Smiles estaciones *
 ********************/
    
$row=mysql_fetch_array(mysql_query("SELECT * FROM user_items WHERE name='$nick'"));
    if(
$row['estaciones']>=1){
    
$mensaje str_replace(":estaciones:","<embed src='estaciones.swf' wmode='transparent' width='42' height='50' title=':ESTACIONES:'></embed>",$mensaje) ; 
    
$mensaje str_replace(":primavera:","<embed src='estaciones.swf' wmode='transparent' width='42' height='50' title=':PRIMAVERA:'></embed>",$mensaje) ; 
    
$mensaje str_replace(":invierno:","<embed src='estaciones.swf' wmode='transparent' width='42' height='50' title=':INVIERNO:'></embed>",$mensaje) ; 
    
$mensaje str_replace(":verano:","<embed src='estaciones.swf' wmode='transparent' width='42' height='50' title=':VERANO:'></embed>",$mensaje) ;
        
$mensaje str_replace(":otoño:","<embed src='estaciones.swf' wmode='transparent' width='42' height='50' title=':OTO&ntilde;O:'></embed>",$mensaje) ; 

    }
 
/********************
 *      BBCodes      *
 ********************/
$mensaje str_replace("[u]","<u>",$mensaje) ; $mensaje str_replace("[/u]","</u>",$mensaje) ; 
$mensaje str_replace("[u]","<u>",$mensaje) ; $mensaje str_replace("[/u]","</u>",$mensaje) ; 
$post[]='<strong>'.$nick.':</strong> '.$mensaje

if(!empty(
$post)) 
echo 
implode('<br>',$post); 
else 
echo 
"No hay comentarios."
echo 
'<div id="ultimo"></div>'
}elseif(
$_POST['t']=="insert"){ 
$name=$_POST['name']; 
$fecha=@date('d-m-Y'); 
$sala=$_POST['sala']; 
$cont=nl2br(addslashes(strip_tags($_POST['cont']))); 
$campos=array('name','fecha','cont','sala'); 
$datos=array( $name$fecha ,$cont$sala); 
$c=implode(',',$campos); 
$d='\''.implode("','",$datos).'\''
$sSQL=sprintf("INSERT INTO %s (%s) VALUES (%s)","'$pre'_contenido",$c,$d); 
$query mysql_query($sSQL); 
$n=mysql_num_rows(mysql_query("SELECT * FROM '$pre'_online WHERE user='".$name."'")); 
if(
$n==0){ 
$campos=array('time','user','sala'); 
$datos=array(  (time())+$seg_inac,$name,$sala); 
$c=implode(',',$campos); 
$d='\''.implode("','",$datos).'\''
$sSQL=sprintf("INSERT INTO %s (%s) VALUES (%s)","'$pre'_online",$c,$d); 
$query mysql_query($sSQL); 
}elseif(
$n==1){ 
$consulta "Update '$pre'_online set time='".(time()+$seg_inac)."', sala='".$_POST['sala']."' WHERE user ='".$name."'"
@
$resultado mysql_query($consulta) or die(mysql_error()); 



?>
Espero que me ayuden, esos son los archivos que edité.

Etiquetas: ajax, chat, mysql, sql, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:13.