Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $chat = "./chatlogs.txt";
- $strdata = $_POST['msg'];
- $username = $_POST['sn'];
- $maxLines = 15;
- $message = '';
- function nameColor($name){
- return substr(md5($name),0,6);
- }
- if(!file_exists($chat)){
- file_put_contents($chat, '');
- }
- $chatLines = explode(PHP_EOL,file_get_contents($chat));
- if(($linesOver = (count($chatLines) - $maxLines)) > 0){
- $chatLines = array_slice($chatLines,$linesOver);
- }
- $chatLines = implode(PHP_EOL,$chatLines);
- if(strlen($_POST['submit']) > 0){
- if (strlen(trim($strdata,' .')) > 0 && strlen($username) > 0){
- $chatLines .= '<span style="font-weight: bold;color: ' . nameColor($username) . ';">' . $username . '</span>: ' . $strdata . "<br />" . PHP_EOL;
- $fh = fopen($chat,'w');
- fwrite($fh, $chatLines);
- fclose($fh);
- }else if(strlen($username) === 0){
- $message = "<font color=\"FF0000\">You must enter a username!</font>";
- }
- }
- ?>
- <html>
- <head>
- <title>Simple Chat Page</title>
- </head>
- <body onLoad="document.getElementById('msg').focus();">
- <?php
- echo $chatLines . PHP_EOL . '<hr />' . PHP_EOL . $message . PHP_EOL;
- ?>
- <form method="POST" autocomplete="off">
- <?php
- if(strlen($username) > 0){
- echo '<input type="hidden" name="sn" value="' . $username . '">';
- }else{
- echo 'Name: <input type="text" size="7" name="sn" value="' . $username . '">';
- }
- ?>
- Message: <input type="text" id="msg" name="msg">
- <input type="submit" name="submit" value="Send">
- <input type="submit" name="submit" value="Check for new messages">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement