elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  [PHP] DH Chat 0.5
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [PHP] DH Chat 0.5  (Leído 1,291 veces)
BigBear


Desconectado Desconectado

Mensajes: 545



Ver Perfil
[PHP] DH Chat 0.5
« en: 4 Diciembre 2015, 16:23 pm »

Un simple chat que hice en PHP que tiene las siguientes opciones :

  • Solo permite 10 mensajes por lo que borra por antiguedad
  • Filtra malas palabras
  • Se pueden borrar comentarios desde el administrador

Una imagen :



Los codigos :

index.php

Código
  1. <?php
  2.  
  3. // DH Chat 0.5
  4. // (C) Doddy Hackman 2015
  5.  
  6. // Login
  7.  
  8. $username = "admin"; // Edit
  9. $password = "21232f297a57a5a743894a0e4a801fc3"; // Edit
  10.  
  11. //
  12.  
  13. $index = "admin.php"; // Edit
  14.  
  15. if (isset($_GET['poraca'])) {
  16.  
  17.    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  18. <html xmlns="http://www.w3.org/1999/xhtml">
  19.   <head>
  20.      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  21.      <title>Login</title>
  22.      <link rel="shortcut icon" href="images/icono.png">
  23.      <link href="style.css" rel="stylesheet" type="text/css" />
  24.   </head>
  25.   <body>
  26.      <center><br>
  27.         <div class="post">
  28.            <h3>Login</h3>
  29.            <div class="post_body">
  30.               <img src="images/login.jpg" width="562" height="440" />
  31.               <br />
  32.               <form action="" method=POST>
  33.                  Username : <input type=text size=30 name=username /><br /><br />
  34.                  Password : <input type=password size=30 name=password /><br /><br />
  35.                  <input type=submit name=login style="width: 100px;" value=Login /><br /><br />
  36.               </form>
  37.            </div>
  38.         </div>
  39.      </center>
  40.   </body>
  41. </html>';
  42.  
  43.    if (isset($_POST['login'])) {
  44.  
  45.        $test_username = $_POST['username'];
  46.        $test_password = md5($_POST['password']);
  47.  
  48.        if ($test_username == $username && $test_password == $password) {
  49.            setcookie("login", base64_encode($test_username . "@" . $test_password));
  50.            echo "<script>alert('Welcome idiot');</script>";
  51.            $ruta = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $index;
  52.            echo '<meta http-equiv="refresh" content="0; url=' . htmlentities($ruta) . '" />';
  53.        } else {
  54.            echo "<script>alert('Fuck You');</script>";
  55.        }
  56.    }
  57.  
  58. } else {
  59.    echo '<meta http-equiv="refresh" content="0; url=http://www.petardas.com" />';
  60. }
  61.  
  62. // The End ?
  63.  
  64. ?>
  65.  

admin.php

Código
  1. <?php
  2.  
  3. // DH Chat 0.5
  4. // (C) Doddy Hackman 2015
  5.  
  6.  
  7. // Login
  8.  
  9. $username = "admin"; // Edit
  10. $password = "21232f297a57a5a743894a0e4a801fc3"; // Edit
  11.  
  12. // DB
  13.  
  14. $host  = "localhost"; // Edit
  15. $userw = "root"; // Edit
  16. $passw = ""; // Edit
  17. $db    = "chat"; // Edit
  18.  
  19. if (isset($_COOKIE['login'])) {
  20.  
  21.    $st = base64_decode($_COOKIE['login']);
  22.  
  23.    $plit = explode("@", $st);
  24.    $user = $plit[0];
  25.    $pass = $plit[1];
  26.  
  27.    if ($user == $username and $pass == $password) {
  28.  
  29.        echo '
  30. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  31. <html xmlns="http://www.w3.org/1999/xhtml">
  32.   <head>
  33.      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  34.      <title>DH Chat 0.5</title>
  35.      <link rel="shortcut icon" href="images/icono.png">
  36.      <link href="style.css" rel="stylesheet" type="text/css" />
  37.   </head>
  38.   <body>
  39.   <center>
  40.   ';
  41.  
  42.        mysql_connect($host, $userw, $passw);
  43.        mysql_select_db($db);
  44.  
  45.        echo '         <br><img src="images/chat.png" /><br>';
  46.  
  47.        if (isset($_POST['instalar'])) {
  48.  
  49.            $todo = "create table mensajes (
  50. id_comentario int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  51. mensaje TEXT NOT NULL,
  52. apodo VARCHAR(255) NOT NULL,
  53. PRIMARY KEY (id_comentario));
  54. ";
  55.  
  56.            $todo2 = "create table insultos (
  57. id_insulto int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  58. mensaje TEXT NOT NULL,
  59. PRIMARY KEY (id_insulto));
  60. ";
  61.  
  62.            if (mysql_query($todo)) {
  63.                if (mysql_query($todo2)) {
  64.  
  65.                    $insultos = array(
  66.                        "lammer",
  67.                        "lamer",
  68.                        "maricon",
  69.                        "noob"
  70.                    );
  71.  
  72.                    foreach ($insultos as $con) {
  73.                        @mysql_query("INSERT INTO insultos(id_insulto,mensaje)values(NULL,'$con')");
  74.                    }
  75.  
  76.                    echo "<script>alert('Installed');</script>";
  77.                    echo '<meta http-equiv="refresh" content=0;URL=>';
  78.                }
  79.            } else {
  80.                echo "<script>alert('Error');</script>";
  81.            }
  82.        }
  83.  
  84.        if (mysql_num_rows(mysql_query("show tables like 'mensajes'"))) {
  85.  
  86.            //
  87.  
  88.            $re = mysql_query("select * from mensajes order by id_comentario ASC");
  89.  
  90.            if (isset($_GET['id'])) {
  91.                if (is_numeric($_GET['id'])) {
  92.                    if (@mysql_query("delete from mensajes where id_comentario='" . $_GET['id'] . "'")) {
  93.                        echo "<script>alert('Comment deleted');</script>";
  94.                    } else {
  95.                        echo "<script>alert('Error');</script>";
  96.                    }
  97.                }
  98.            }
  99.  
  100.            $sql       = "select id_comentario from mensajes";
  101.            $resultado = mysql_query($sql);
  102.            $cantidad  = mysql_num_rows($resultado);
  103.  
  104.            echo '
  105.            <div class="post">
  106.                <h3>Comments : ' . $cantidad . '</h3>
  107.                   <div class="post_body"><br>';
  108.            if ($cantidad <= 0) {
  109.                echo '<b>No entries found</b><br>';
  110.            } else {
  111.                echo "<table>";
  112.                echo "<td><b>ID</b></td><td><b>Nick</b></td><td><b>Text</b></td><td><b>Option</b></td><tr>";
  113.  
  114.                while ($ver = mysql_fetch_array($re)) {
  115.                    echo "<td>" . htmlentities($ver[0]) . "</td><td>" . htmlentities($ver[2]) . "</td><td>" . htmlentities($ver[1]) . "</td><td><a href=?id=" . htmlentities($ver[0]) . ">Delete</a></td><tr>";
  116.                }
  117.  
  118.                echo "</table>";
  119.  
  120.            }
  121.  
  122.            echo '                <br></div>
  123.            </div>';
  124.  
  125.            if (isset($_POST['new_word'])) {
  126.                $in = $_POST['word'];
  127.                if (@mysql_query("INSERT INTO insultos(id_insulto,mensaje)values(NULL,'$in')")) {
  128.                    echo "<script>alert('Word added');</script>";
  129.                } else {
  130.                    echo "<script>alert('Error');</script>";
  131.                }
  132.            }
  133.  
  134.            if (isset($_GET['del_word'])) {
  135.                if (is_numeric($_GET['del_word'])) {
  136.                    if (@mysql_query("delete from insultos where id_insulto='" . $_GET['del_word'] . "'")) {
  137.                        echo "<script>alert('Word deleted');</script>";
  138.                    } else {
  139.                        echo "<script>alert('Error');</script>";
  140.                    }
  141.                }
  142.            }
  143.  
  144.            echo '
  145.         <div class="post">
  146.            <h3>Block words</h3>
  147.            <div class="post_body"><br>
  148.            ';
  149.  
  150.            echo "
  151. <form action='' method=POST>
  152. <b>Word : </b><input type=text name=word>
  153. <input type=submit name=new_word style='width: 100px;' value=Add>
  154. </form>";
  155.  
  156.            echo '
  157.            <br>
  158.            </div>
  159.         </div>
  160.         ';
  161.  
  162.  
  163.            $sql       = "select id_insulto from insultos";
  164.            $resultado = mysql_query($sql);
  165.            $cantidad  = mysql_num_rows($resultado);
  166.  
  167.            echo '
  168.         <div class="post">
  169.            <h3>Words blocked : ' . $cantidad . '</h3>
  170.            <div class="post_body"><br>
  171.            ';
  172.  
  173.            $rea = mysql_query("select * from insultos order by id_insulto ASC");
  174.  
  175.            if ($cantidad <= 0) {
  176.                echo '<b>No entries found</b><br>';
  177.            } else {
  178.                echo "<table>";
  179.                echo "<td>ID</td><td>Word</td><td>Option</td><tr>";
  180.                while ($ver = mysql_fetch_array($rea)) {
  181.                    echo "<td>" . htmlentities($ver[0]) . "</td><td>" . htmlentities($ver[1]) . "</td><td><a href=?del_word=" . htmlentities($ver[0]) . ">Delete</a></td><tr>";
  182.                }
  183.  
  184.                echo "</table>";
  185.  
  186.            }
  187.  
  188.            echo '
  189.            <br>
  190.            </div>
  191.         </div>
  192.         ';
  193.  
  194.        } else {
  195.  
  196.            echo '
  197.            <div class="post">
  198.                <h3>Installer</h3>
  199.                   <div class="post_body">';
  200.  
  201.            echo "
  202. <form action='' method=POST>
  203. <h2>Do you want install DH Chat 0.5 ?</h2><br>
  204. <input type=submit name=instalar style='width: 100px;' value=Install>
  205. </form><br>";
  206.            echo '                </div>
  207.            </div>';
  208.        }
  209.  
  210.        echo '  
  211.   <br><h3>(C) Doddy Hackman 2015</h3><br>
  212.   </center>
  213.   </body>
  214. </html>';
  215.  
  216.        mysql_close();
  217.        exit(1);
  218.  
  219.    } else {
  220.        echo "<script>alert('Fuck You');</script>";
  221.    }
  222.  
  223. } else {
  224.    echo '<meta http-equiv="refresh" content="0; url=http://www.petardas.com" />';
  225. }
  226.  
  227. // The End ?
  228.  
  229. ?>
  230.  

style.css

Código
  1. /*
  2.  
  3. ==-----------------------------------==
  4. || Name : DH Theme                   ||
  5. || Version : 0.8                     ||  
  6. || Author : Doddy H                  ||
  7. || Description: Templante            ||
  8. || Date : 14/1/2015                  ||
  9. ==-----------------------------------==
  10.  
  11. */
  12.  
  13. body {
  14. background:transparent url("images/fondo.jpg") repeat scroll 0 0;
  15. color:gray;
  16. font-family:helvetica,arial,sans-serif;
  17. font-size:14px;
  18. text-align:center;
  19. }
  20.  
  21. a:link {
  22. text-decoration:none;
  23. color:orange;
  24. }
  25. a:visited {
  26. color:orange;
  27. }
  28. a:hover {
  29. color:orange;
  30. }
  31.  
  32. td,tr {
  33. border-style:solid;
  34. border-color: gray;
  35. border-width: 1px;
  36. background: black;
  37. border: solid #222 2px;
  38. color:gray;
  39. font-family:helvetica,arial,sans-serif;
  40. font-size:14px;
  41. text-align:center;
  42.  
  43. word-wrap: break-word;
  44. word-break:break-all;
  45. }
  46.  
  47. input {
  48. border-style:solid;
  49. border-color: gray;
  50. border-width: 1px;
  51. background: black;
  52. border: solid #222 2px;
  53. color:gray;
  54. font-family:helvetica,arial,sans-serif;
  55. font-size:14px;
  56. }
  57.  
  58. .post {
  59. background-color:black;
  60. color:gray;
  61. margin-bottom:10px;
  62. width:600px;
  63. word-wrap: break-word;
  64. }
  65.  
  66. .post h3 {
  67. background-color:black;
  68. color:orange;
  69. background-color:#000;
  70. border: solid #222 2px;
  71. -webkit-border-radius: 4px;
  72. -moz-border-radius: 4px;
  73. border-radius: 4px;
  74. padding:5px 10px;
  75. }
  76.  
  77. .post_body {
  78. background-color:black;
  79. margin:-20px 0 0 0;
  80. color:white;
  81. background-color:#000;
  82. border: solid #222 2px;
  83. -webkit-border-radius: 4px;
  84. -moz-border-radius: 4px;
  85. border-radius: 4px;
  86. padding:5px 10px;
  87. }
  88.  
  89. /* The End ? */
  90.  

chat.php

Código
  1. <?php
  2.  
  3. //DH Chat 0.5
  4. //(C) Doddy Hackman 2015
  5.  
  6. // DB
  7.  
  8. $host = "localhost"; // Edit
  9. $user = "root"; // Edit
  10. $pass = ""; // Edit
  11. $db   = "chat"; // Edit
  12.  
  13. //
  14.  
  15.  
  16. mysql_connect($host, $user, $pass);
  17.  
  18. echo '<link href="chat.css" rel="stylesheet" type="text/css" />';
  19.  
  20. echo "<table border=0 width='210' style='table-layout: fixed'>";
  21. echo "<td><b>DH Chat 0.5</b></td><tr>";
  22.  
  23.  
  24. $sumo = mysql_query("SELECT MAX(id_comentario) FROM mensajes");
  25.  
  26. $s = mysql_fetch_row($sumo);
  27.  
  28. foreach ($s as $d) {
  29.    $total = $d;
  30. }
  31.  
  32. $test = $total - 10;
  33.  
  34. if ($test <= 0) {
  35.    next;
  36. } else {
  37.    $resto = $test;
  38.  
  39.    for ($i = 1; $i <= $resto; $i++) {
  40.        @mysql_query("DELETE FROM mensajes where id_comentario='$i'");
  41.    }
  42. }
  43.  
  44. $re = @mysql_query("select * from mensajes order by id_comentario DESC");
  45.  
  46. while ($ver = @mysql_fetch_array($re)) {
  47.    echo "<td><b>" . htmlentities($ver[2]) . "</b> : " . htmlentities($ver[1]) . "</td><tr>";
  48. }
  49.  
  50.  
  51. echo "<br><br><td><br><b>Comment</b><br><br>    
  52. <form action='' method=POST>
  53. Nick : <input type=text name=apodo size=20><br><br>
  54. Text : <input type=text name=msg size=20><br><br>
  55. <input type=submit name=chatentro style='width: 100px;' value=Send>
  56. </form>
  57. <tr>
  58. <td><b>Coded By Doddy H</b></td><tr>
  59. </table>";
  60.  
  61.  
  62. if (isset($_POST['chatentro'])) {
  63.  
  64.    $sumo = mysql_query("SELECT MAX(id_comentario) FROM mensajes");
  65.  
  66.    $s = mysql_fetch_row($sumo);
  67.  
  68.    foreach ($s as $d) {
  69.        $x_id = $d + 1;
  70.    }
  71.  
  72.    $apodo   = htmlentities(addslashes($_POST['apodo']));
  73.    $mensaje = htmlentities(addslashes($_POST['msg']));
  74.  
  75.    $apodo   = substr($apodo, 0, 70);
  76.    $mensaje = substr($mensaje, 0, 70);
  77.  
  78.    $rex = mysql_query("select mensaje from insultos");
  79.  
  80.    while ($con = mysql_fetch_array($rex)) {
  81.        $mensaje = str_replace($con[0], "#$!*", $mensaje);
  82.        $apodo   = str_replace($con[0], "#$!*", $apodo);
  83.    }
  84.  
  85.    if (is_numeric($x_id)) {
  86.        @mysql_query("INSERT INTO mensajes(id_comentario,apodo,mensaje)values('$x_id','$apodo','$mensaje')");
  87.    }
  88.  
  89.    echo '<meta http-equiv="refresh" content=0;URL=>';
  90.  
  91. }
  92.  
  93.  
  94. // The End ?
  95.  
  96. ?>
  97.  

chat.css

Código
  1. /*
  2.  
  3. ==-----------------------------------==
  4. || Name : DH Theme                   ||
  5. || Version : 0.8                     ||  
  6. || Author : Doddy H                  ||
  7. || Description: Templante            ||
  8. || Date : 14/1/2015                  ||
  9. ==-----------------------------------==
  10.  
  11. */
  12.  
  13. body {
  14. color:gray;
  15. font-family:helvetica,arial,sans-serif;
  16. font-size:14px;
  17. text-align:center;
  18. }
  19.  
  20. a:link {
  21. text-decoration:none;
  22. color:orange;
  23. }
  24. a:visited {
  25. color:orange;
  26. }
  27. a:hover {
  28. color:orange;
  29. }
  30.  
  31. td,tr {
  32. border-style:solid;
  33. border-color: gray;
  34. border-width: 1px;
  35. background: black;
  36. border: solid #222 2px;
  37. color:gray;
  38. font-family:helvetica,arial,sans-serif;
  39. font-size:14px;
  40. text-align:center;
  41.  
  42. word-wrap: break-word;
  43. word-break:break-all;
  44. }
  45.  
  46. input {
  47. border-style:solid;
  48. border-color: gray;
  49. border-width: 1px;
  50. background: black;
  51. border: solid #222 2px;
  52. color:gray;
  53. font-family:helvetica,arial,sans-serif;
  54. font-size:14px;
  55. }
  56.  
  57. .post {
  58. background-color:black;
  59. color:gray;
  60. margin-bottom:10px;
  61. width:600px;
  62. word-wrap: break-word;
  63. }
  64.  
  65. .post h3 {
  66. background-color:black;
  67. color:orange;
  68. background-color:#000;
  69. border: solid #222 2px;
  70. -webkit-border-radius: 4px;
  71. -moz-border-radius: 4px;
  72. border-radius: 4px;
  73. padding:5px 10px;
  74. }
  75.  
  76. .post_body {
  77. background-color:black;
  78. margin:-20px 0 0 0;
  79. color:white;
  80. background-color:#000;
  81. border: solid #222 2px;
  82. -webkit-border-radius: 4px;
  83. -moz-border-radius: 4px;
  84. border-radius: 4px;
  85. padding:5px 10px;
  86. }
  87.  
  88. /* The End ? */
  89.  

test.php

Código
  1. <body background="test.jpg">
  2.  
  3. <?php
  4.  
  5. include("chat.php");
  6.  
  7. ?>
  8.  

Si quieren bajar el programa lo pueden hacer de aca.

Cualquier sugerencia para mejorar este proyecto diganla para mejorar.

Saludos.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
chat
Sugerencias y dudas sobre el Foro
thinkhacker 1 2,116 Último mensaje 15 Abril 2005, 05:53 am
por + enrique ZP
El chat no oficial de elhacker.net (http://the-chat.tk/ )
Sugerencias y dudas sobre el Foro
YST 8 5,839 Último mensaje 3 Abril 2009, 17:29 pm
por #!drvy
Chat en Foro SMF con autentificacion ( sin ella no podran ablar en el chat )
PHP
XXXXXX 3 5,667 Último mensaje 28 Abril 2010, 02:19 am
por XXXXXX
Chat para publico y chat privado
Desarrollo Web
ganondolf 2 3,435 Último mensaje 30 Diciembre 2014, 03:10 am
por Varlch
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines