ironjedddi

Untitled

Jan 7th, 2021
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.20 KB | None | 0 0
  1. <?php
  2. if (isset($_GET['enSubmit']) && isset($_GET['uname']) && isset($_GET['rname'])){
  3.     echo'<meta http-equiv="refresh" content="10">';
  4.     $room=$_GET['rname'];
  5.     $uname=$_GET['uname'];
  6.     if (!is_dir($room)) mkdir($room);
  7.     $files = scandir($room);
  8.     foreach ($files as $user){
  9.         if ($user=='.' || $user=='..') continue;
  10.         $handle=fopen("$room/$user",'r');
  11.         $time = fread($handle, filesize("$room/$user"));
  12.         fclose($handle);
  13.         if ((time()-$time)>1) unlink("$room/$user");
  14.     }
  15.     $contents='';
  16.     $filename="$room.txt";
  17.     if (file_exists($filename)){
  18.         $handle = fopen($filename, "r");
  19.         $contents = fread($handle, filesize($filename));
  20.         fclose($handle);   
  21.     }
  22.     $handle = fopen("$room/$uname", "w");
  23.     fwrite($handle, time());
  24.     fclose($handle);
  25.    
  26.     $files = scandir($room);
  27.     $users='';
  28.     foreach ($files as $user) if ($user!='.' && $user!='..') $users.=$user."\n";
  29.    
  30.     if (isset($_POST['Send'])){
  31.         $text=$_POST['txt'];
  32.         $contents.="$uname: $text";
  33.         $handle = fopen("$filename", "a");
  34.         fwrite($handle, "$uname: $text\n");
  35.         fclose($handle);
  36.     }
  37.     $filename = "$room.txt";
  38. if (file_exists($filename)) {
  39.     echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
  40. }
  41. ?>
  42. <body OnLoad="document.myform.txt.focus()">
  43. <form action="" method="post" name="myform">
  44. <table style="border: 1px solid #000000;width: 752px" align="center">
  45.     <tr>
  46.         <td style="font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: center;width: 537; color: #2214B9;border-style: solid;border-width: 1px; height: 350px;">
  47.             <textarea readonly="readonly" name="txtchat" style="width: 581px; color: #000000; height: 365px; background-color: #F4F8D1; font-family: 'times New Roman', Times, serif; font-size: 12pt;"><?php echo "Welcome to the $room chatroom...\n$contents"?> </textarea>
  48.         </td>
  49.         <td style="font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: center;color: #2214B9;border-style: solid;border-width: 1px; height: 349px; width: 143px;">
  50.             <textarea readonly="readonly"  contenteditable="false"  name="txtusers" style=";width: 163px; height: 365px; background-color: #D1F8D8; font-family: 'times New Roman', Times, serif; font-size: 12pt; font-weight: bold; text-align: center;"><?php echo $users?></textarea>
  51.         </td>
  52.     </tr>
  53.     <tr>
  54.         <td style="width: 537; border-style: solid;border-width: 1px;text-align: left; height: 39px; font-size: 14pt;">
  55.         <textarea id="txtt"  name="txt" style="width: 581px; height: 79px; font-family: 'times New Roman', Times, serif; font-size: 12pt"></textarea></td>
  56.         <td style="border-style: solid;border-width: 1px; height: 39px;padding-left: 8px; width: 143px; text-align: center;">
  57.         <?php $fi = new FilesystemIterator (__DIR__ . "/$room"); printf("/%d Votes to Terminate", iterator_count($fi)); ?></td>
  58.     </tr>
  59.     <script>
  60. var input = document.getElementById("txtt");
  61. input.addEventListener("keyup", function(event) {
  62.   if (event.keyCode === 13) {
  63.    event.preventDefault();
  64.    document.getElementById("send").click();
  65.   }
  66. });
  67. </script>
  68. </table>
  69. <input id="send" name="Send" style="color: transparent; background-color: transparent; border-color: transparent; cursor: default;" type="submit" value="">
  70. </form>
  71. <?php
  72. }else {
  73. ?>
  74. <form method="GET" action="">
  75. <table style="border: 1px solid #000000;width: 452px" align="center">
  76.     <tr>
  77.         <td style="font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 432px; color: #2214B9;;border-style: solid;border-width: 1px;">Name:</td>
  78.         <td style="border-style: solid; border-width: 1px; font-family: 'Times New Roman', Times, serif; font-size: 17pt; text-align: left; color: #2214B9; width: 430px;">
  79.         <input name="uname" style="font-size: medium; width: 260px; color: #B01919;"></td>
  80.     </tr>
  81.     <tr>
  82.         <td style="font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 432px; color: #2214B9;border-style: solid;border-width: 1px;">Select Room:</td>
  83.         <td style="border-style: solid; border-width: 1px; font-family: 'Times New Roman', Times, serif; font-size: 17pt; text-align: left; color: #2214B9; width: 430px;">
  84.         <select name="rname" style="width: 260px; font-size: medium; color: #B01919;">
  85.         <option selected="">Room 1</option>
  86.         <option>Room 2</option>
  87.         <option>Room 3</option>
  88.         </select></td>
  89.     </tr>
  90.     <tr>
  91.         <td style="font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: center; color: #2214B9; border-left-style: solid; border-left-width: 1px; border-right-style: none; border-right-width: medium; border-top-style: solid; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px; padding-top:10px;padding-bottom:10px" colspan="2">
  92.         <input name="enSubmit" style="width: 118px; height: 63px; font-size: 30pt; font-family: 'Times New Roman', Times, serif; color: #19B024;" type="submit" value="Enter"></td>
  93.     </tr>
  94. </table>
  95. </form>
  96. <?php
  97. }
  98. ?>
  99. <script>
  100. el=document.myform.txtt
  101.     if (typeof el.selectionStart == "number") {
  102.         el.selectionStart = el.selectionEnd = el.value.length;
  103.     } else if (typeof el.createTextRange != "undefined") {
  104.         el.focus();
  105.         var range = el.createTextRange();
  106.         range.collapse(false);
  107.         range.select();
  108.     }</script>
  109. </body>
  110. <?php
  111.  
  112. ?>
  113.  
Advertisement
Add Comment
Please, Sign In to add comment