Hacer Un Chat Con Php y Mysql
Hola,
Hice muchos foros con ajax y php, y este es el mejor que e echo.
Tiene:
* Lista de usuario conectado en la sala.
* Distintas salas
* Configuraciones
* BBcodes
* Echo en AJAX
Este es la base que hice, que de este cree mejores. No tiene mucha seguridad. Y es libre de uso.
chat.php
CódigoPHP:
<?php
///////////////////////////////////////////////////////////////////
// CREADO POR PATO12 DE FOROSDELWEB.COM
// WWW.HALFMUSIC.COM.AR
///////////////////////////////////////////////////////////////////
if($_POST){
$sala="General";
include('config.php');
$user=addslashes($_POST['nick']);
$n=mysql_num_rows(mysql_query("SELECT * FROM online WHERE user='".$user."'"));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)","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 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)","online",$c,$d);
$query = mysql_query($sSQL);
}else{
die("El nick ya existe.");
}
}
?>
<script type="text/javascript"><!--
var segundos=3;
var user="<?=stripslashes($user)?>";
var sala="general";
var acSegMill=(segundos==0 || segundos>10)? 1000 : segundos*1000;
-->
</script>
<script type="text/javascript" src="chat.js"></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;...
Regístrate para leer el documento completo.