Guest User

Untitled

a guest
Apr 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. <html>
  2.  
  3. <title>Chatbox 1.0</title>
  4.  
  5. <link type="text/css" rel="stylesheet" href="CSS/cb.css">
  6.  
  7. <div class="head">
  8.  
  9. <div class="main">
  10.  
  11. </div>
  12.  
  13. <div class="des">
  14.  
  15. This is beta version 1.0 of the Chatbox!
  16.  
  17. </div>
  18.  
  19. </div>
  20.  
  21. <?php
  22. session_start();
  23. if($_SESSION['username'] == "")
  24. {
  25. echo "<script type='text/javascript'>alert('Please sign in to use our service.');</script>";
  26.  
  27. echo "<script>setTimeout("location.href = 'http://chatboxdev.x10host.com/';",100);
  28. </script>";
  29. exit();
  30.  
  31. }
  32. $subject = $_SESSION['chat'];
  33.  
  34. if($subject == ""){
  35. $subject ="helloworld";
  36. }
  37. elseif(file_exists($subject)){
  38. $myfile = fopen($subject,"r");
  39.  
  40. if(strpos("," . base64_decode($_SESSION['username']))===FALSE){
  41. echo "<script type='text/javascript'>alert('You do not have permission to access this chat.');
  42. </script>";
  43.  
  44. echo "<script>setTimeout("location.href = 'http://chatboxdev.x10host.com/';",100);</script>";
  45. }
  46. }
  47.  
  48. echo "signed in as " . base64_decode($_SESSION['username']);
  49.  
  50. $usernam = "chatboxd_cbox";
  51. $servername = "198.91.81.8";
  52. $password = "cbox";
  53.  
  54. $conn = new mysqli($servername, $usernam, $password);
  55.  
  56.  
  57. // Check connection
  58. if
  59. ($conn->connect_error)
  60. {
  61. die("Connection failed: " . $conn->connect_error);
  62. }
  63. echo "
  64. <br>Connected successfully to " . $_SESSION['chat'] ;
  65.  
  66. $msg = "";
  67.  
  68. if(isset($_POST['submit']))
  69. {
  70. sendmsg();
  71. getmsg();
  72. }
  73.  
  74. if(isset($_POST['refresh']))
  75. {
  76. getmsg();
  77. }
  78.  
  79. if(isset($_POST['switch']))
  80. {
  81. $GLOBALS['subject'] = base64_encode(test_input($_POST["targetchat"]));
  82.  
  83. $_SESSION['chat'] =test_input($_POST["targetchat"]);
  84.  
  85.  
  86. getmsg();
  87.  
  88. }
  89.  
  90. if(isset($_POST['logout']))
  91. {
  92. session_destroy();
  93. echo "<script type='text/javascript'>alert('You have logged out.');
  94. </script>";
  95.  
  96. echo "<script>setTimeout("location.href = 'http://chatboxdev.x10host.com/index.php';",100);
  97. </script>";
  98. exit();
  99. }
  100. function sendmsg(){
  101. // define variables and set to empty values
  102.  
  103. if ($_SERVER["REQUEST_METHOD"] == "POST")
  104. {
  105. $msg = base64_encode(test_input($_POST["msg"]));
  106.  
  107. $username = $_SESSION['username'];
  108.  
  109. $usernam = "chatboxd_cbox";
  110.  
  111. $servername = "198.91.81.8";
  112.  
  113. $password = "cbox";
  114. $db = "chatboxd_chats";
  115.  
  116. $conn = new mysqli($servername, $usernam, $password,$db);
  117.  
  118. $datetim = base64_encode(date("r"));
  119.  
  120. $sql = "INSERT INTO " . $GLOBALS['subject'] ."
  121. VALUES ('$username','$datetim','$msg')";
  122.  
  123. if ($conn->query($sql) === TRUE) {
  124. } else {
  125. echo "Error: " . $sql . "<br>" . $conn->error;
  126. }
  127. }
  128. }
  129.  
  130. function getmsg(){
  131. $usernam = "chatboxd_cbox";
  132. $servername = "198.91.81.8";
  133. $password = "cbox";
  134. $db = "chatboxd_chats";
  135.  
  136. $conn = new mysqli($servername, $usernam, $password,$db);
  137.  
  138. $sql = "SELECT * FROM " .$GLOBALS['subject'];
  139. $result = $conn->query($sql);
  140.  
  141. if ($result->num_rows > 0) {
  142. while($row = $result->fetch_assoc())
  143. {
  144. echo "<br>" . base64_decode($row["user"]). " said: " . base64_decode($row["message"]). " on " . base64_decode($row["datetime"])."<br>";
  145. }
  146. }
  147. else {
  148. echo "<br>No messages were found to display! Start sending them now!";
  149. }
  150.  
  151. if ($conn->query($sql)===FALSE){
  152. echo("Error: " . $sql . "<br>" . $conn->error);
  153. }
  154. }
  155. function test_input($data)
  156. {
  157. $data = trim($data);
  158. $data = stripslashes($data);
  159. $data = htmlspecialchars($data);
  160. return $data;
  161. }
  162. ?>
  163.  
  164. <div class="chatbox">
  165. <p name = "subject">
  166. hello world.txt
  167. </p>
  168.  
  169. <div class="chatlogs" id="sc" onload="sc();">
  170. <?php
  171.  
  172. ?>
  173.  
  174. </div>
  175.  
  176. </div>
  177.  
  178. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  179.  
  180. Message:<textarea name ="msg"></textarea>
  181.  
  182. <input type ="submit" name = "submit" value ="Send">
  183.  
  184. <input type="submit" name="logout" class="logout" value="Logout" />
  185.  
  186.  
  187. <input type="submit" name="switch" class="switch" value="Change to another chat:" />
  188. <input name = "targetchat"/>
  189.  
  190. </form>
  191. </body>
  192. <script>
  193. var objDiv = document.getElementById("sc");
  194. objDiv.scrollTop = objDiv.scrollHeight;
  195.  
  196. function sc(){
  197. setTimeout(scroll(), 100);
  198. }
  199.  
  200. function scroll(){
  201. var objDiv = document.getElementById("sc");
  202.  
  203. objDiv.scrollTop = objDiv.scrollHeight;
  204. }
  205.  
  206. setTimeout(function(){
  207. window.location.reload(1);
  208. }, 60000);
  209.  
  210. </script>
  211.  
  212.  
  213. </html>
Add Comment
Please, Sign In to add comment