Una nueva version del simple chat que habia hecho hace un tiempo.
El codigo del chat
<?php
//Mini Chat 0.3
//Coded By Doddy H
//Datos del a DB
$host = "localhost";
$user = "root";
$pass = "";
$db = "chat";
//
//Colores
$fondo = "black";
$color = "#00FF00";
//
echo "
<style>
.main {
word-wrap: break-word;
word-break:break-all;
margin : -287px 0px 0px -490px;
border : White solid 1px;
BORDER-COLOR: $color;
background-color:$fondo;
color:$color;
}
.otro {
background-color:$fondo;
color:$color;
BORDER-COLOR: $color;
}
</style>";
mysql_connect($host,$user,$pass);
mysql_select_db($db);
echo "<table border=0 width='210' style='table-layout: fixed'>";
echo "<td class=main><b>Mini Chat 0.3</b></td><tr class=main>";
$sumo = mysql_query("SELECT MAX(id_comentario) FROM mensajes");
$s = mysql_fetch_row($sumo);
foreach ($s as $d) {
$total = $d;
}
$test = $total - 10;
if ($test <= 0) {
next;
} else {
$resto = $test;
for ($i = 1; $i <= $resto; $i++) {
@mysql_query("DELETE FROM mensajes where id_comentario='$i'");
}
}
$re = @mysql_query("select * from mensajes order by id_comentario DESC");
while ($ver = @mysql_fetch_array($re)) {
echo "<td class=main><b>".$ver[2]."</b>:".$ver[1]."</td><tr class=main>";
}
echo "<br><br><td class=main><br><b>Dejar mensaje</b><br><br>
<form action='' method=POST>
Apodo : <input class=otro type=text name=apodo size=25><br>
Texto : <input class=otro type=text name=msg size=25><br><br>
<input class=otro type=submit name=chatentro value=Mandar>
</form>
<tr>
<td class=main><b>Coded By Doddy H</b></td><tr class=main>
</table>";
if (isset($_POST['chatentro'])) {
$sumo = mysql_query("SELECT MAX(id_comentario) FROM mensajes");
$s = mysql_fetch_row($sumo);
foreach ($s as $d) {
$x_id = $d+1;
}
$apodo = htmlentities(addslashes($_POST['apodo']));
$mensaje = htmlentities(addslashes($_POST['msg']));
$apodo = substr($apodo,0,70);
$mensaje = substr($mensaje,0,70);
$rex = mysql_query("select mensaje from insultos");
while ($con = mysql_fetch_array($rex)) {
$mensaje = str_replace($con[0],"#$!*",$mensaje);
$apodo = str_replace($con[0],"#$!*",$apodo);
}
@mysql_query("INSERT INTO mensajes(id_comentario,apodo,mensaje)values('$x_id','$apodo','$mensaje')");
echo '<meta http-equiv="refresh" content=0;URL=>';
}
mysql_close();
// The End ?
?>
El administrador.
<?php
//Mini Chat 0.3 Admin
//Datos para el login
$username = "admin";
$password = "21232f297a57a5a743894a0e4a801fc3"; //admin
//
//Datos para la DB
$host = "localhost";
$userw = "root";
$passw = "";
$db = "chat";
//
if (isset($_COOKIE['portal'])) {
$st = base64_decode($_COOKIE['portal']);
$plit = split("@",$st);
$user = $plit[0];
$pass = $plit[1];
if ($user == $username and $pass == $password) {
echo "<title>Mini Chat 0.3</title>";
mysql_connect($host,$userw,$passw);
mysql_select_db($db);
if(isset($_POST['instalar'])) {
$todo = "create table mensajes (
id_comentario int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
mensaje TEXT NOT NULL,
apodo VARCHAR(255) NOT NULL,
PRIMARY KEY (id_comentario));
";
$todo2 = "create table insultos (
id_insulto int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
mensaje TEXT NOT NULL,
PRIMARY KEY (id_insulto));
";
if (mysql_query($todo)) {
if (mysql_query($todo2)) {
$insultos = array("lammer","lamer","maricon","noob");
foreach ($insultos as $con) {
@mysql_query("INSERT INTO insultos(id_insulto,mensaje)values(NULL,'$con')");
}
echo "<script>alert('Instalado correctamente');</script>";
echo '<meta http-equiv="refresh" content=0;URL=>';
}
} else {
echo "<script>alert('Error');</script>";
}
}
if( mysql_num_rows(mysql_query("show tables like 'mensajes'"))) {
//
$re = mysql_query("select * from mensajes order by id_comentario ASC");
if (isset($_GET['id'])) {
if (is_numeric($_GET['id'])) {
if (@mysql_query("delete from mensajes where id_comentario='".$_GET['id']."'")) {
echo "<script>alert('Comentario borrado');</script>";
} else {
echo "<script>alert('Error');</script>";
}}}
echo "<center><h2>Comentarios encontrados</h2><br><br>";
echo "<table border=1>";
echo "<td><b>ID</b></td><td><b>Apodo</b></td><td><b>Texto</b></td><td><b>Opcion</b></td><tr>";
while ($ver = mysql_fetch_array($re)) {
echo "<td>".htmlentities($ver[0])."</td><td>".htmlentities($ver[2])."</td><td>".htmlentities($ver[1])."</td><td><a href=?id=".htmlentities($ver[0]).">Borrar</a></td><tr>";
}
echo "</table>";
if(isset($_POST['nuevoinsulto'])) {
$in = $_POST['insul'];
@mysql_query("INSERT INTO insultos(id_insulto,mensaje)values(NULL,'$in')");
}
if(isset($_GET['delpu'])) {
if (is_numeric($_GET['delpu'])) {
if (@mysql_query("delete from insultos where id_insulto='".$_GET['delpu']."'")) {
echo "<script>alert('Insulto borrado');</script>";
} else {
echo "<script>alert('Error');</script>";
}}}
echo "<br><br><h2>Bloqueo de insultos</h2><br><br>";
echo "
<form action='' method=POST>
Texto : <input type=text name=insul>
<input type=submit name=nuevoinsulto value=Agregar>
</form>";
echo "<br><br><h2>Insultos encontrados</h2><br><br>";
$rea = mysql_query("select * from insultos order by id_insulto ASC");
echo "<table border=1>";
echo "<td>ID</td><td>Insulto</td><td>Opcion</td><tr>";
while ($ver = mysql_fetch_array($rea)) {
echo "<td>".htmlentities($ver[0])."</td><td>".htmlentities($ver[1])."</td><td><a href=?delpu=".htmlentities($ver[0]).">Borrar</a></td><tr>";
}
echo "</table>";
echo "</center>";
} else {
echo "
<center><br><br>
<form action='' method=POST>
<h2>Deseas instalar Mini Chat 0.3 ?</h2><br><br>
<input type=submit name=instalar value=Instalar>
</form>";
}
mysql_close();
exit(1);
}
}
if (isset($_POST['login'])) {
if ($_POST['user'] == $username and md5($_POST['password']) == $password) {
setcookie("portal",base64_encode($_POST['user']."@".md5($_POST['password'])));
echo "<script>alert('Bienvenido idiota');</script>";
echo '<meta http-equiv="refresh" content=0;URL=>';
} else {
echo "<script>alert('Segui Participando');</script>";
}
} else {
echo "
<title>Mini Chat 0.3</title>
<h1><center>Mini Chat 0.3</center></h1>
<br><br><center>
<form action='' method=POST>
Username : <input type=text name=user><br>
Password : <input type=text name=password><br><br>
<input type=submit name=login value=Enter><br>
</form>
</center><br><br>";
}
// The End ?
?>