Advertisement
garfield

[PHP]: Chat simples em php

Feb 5th, 2012
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. /*
  2.             @Nome: chat simples em php
  3.             @Créditos: SuYaNw Dácio
  4.            
  5.             http://suyanwdacio.blogspot.com
  6. */
  7.  
  8. <?php
  9.     $ar_name = "xat.txt";
  10.     $texto = "";
  11.     $user = " ";
  12.    
  13.     if(isset($_POST['envia']))
  14.     {
  15.         $user = $_POST['nick'];
  16.         if(strlen($_POST['mensagem']) == 0 ||
  17.             strlen($_POST['mensagem'] == NULL))
  18.         {
  19.             echo "<script language=\"javascript\">alert(\"Porfavor, Insira uma mensagem!\")</script>";
  20.         }
  21.         else
  22.         {
  23.             $formatpost = $user." Diz: ".$_POST['mensagem']."\n";
  24.             $back = $formatpost;
  25.             $linha = "";
  26.             if(ContarLinhas($ar_name) >= 24) unlink($ar_name);
  27.             if(ContarLinhas($ar_name) > 0)
  28.             {
  29.                
  30.                 $fp = fopen($ar_name, "r+");
  31.                 if(filesize($ar_name) != 0)
  32.                 {
  33.                     $linha = fread($fp, filesize($ar_name));
  34.                 }
  35.                 fclose($fp);
  36.             }
  37.             $back = $linha.$formatpost;
  38.             $file = fopen($ar_name, "w");
  39.             $aberto = fwrite($file, $back);
  40.             fclose($file);
  41.             $texto = $back;
  42.         }
  43.     }
  44.     echo "<center><form action='#' method='POST'><textarea name='areaxat' cols='80' rows='25'>$texto</textarea><br />Seu Nick:<input type='text' name='nick' value='$user'>Digite sua mensagem:<input type='text' name='mensagem'><input type='submit' name='envia' value='Enviar Mensagem'></form></center>";
  45.    
  46.     function ContarLinhas($arquivo)
  47.     {
  48.         $file = 0;
  49.         if(file_exists($arquivo))$file = count(file($arquivo));
  50.         return $file;
  51.     }
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement