Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- @Nome: chat simples em php
- @Créditos: SuYaNw Dácio
- http://suyanwdacio.blogspot.com
- */
- <?php
- $ar_name = "xat.txt";
- $texto = "";
- $user = " ";
- if(isset($_POST['envia']))
- {
- $user = $_POST['nick'];
- if(strlen($_POST['mensagem']) == 0 ||
- strlen($_POST['mensagem'] == NULL))
- {
- echo "<script language=\"javascript\">alert(\"Porfavor, Insira uma mensagem!\")</script>";
- }
- else
- {
- $formatpost = $user." Diz: ".$_POST['mensagem']."\n";
- $back = $formatpost;
- $linha = "";
- if(ContarLinhas($ar_name) >= 24) unlink($ar_name);
- if(ContarLinhas($ar_name) > 0)
- {
- $fp = fopen($ar_name, "r+");
- if(filesize($ar_name) != 0)
- {
- $linha = fread($fp, filesize($ar_name));
- }
- fclose($fp);
- }
- $back = $linha.$formatpost;
- $file = fopen($ar_name, "w");
- $aberto = fwrite($file, $back);
- fclose($file);
- $texto = $back;
- }
- }
- 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>";
- function ContarLinhas($arquivo)
- {
- $file = 0;
- if(file_exists($arquivo))$file = count(file($arquivo));
- return $file;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement