Advertisement
Guest User

chat.php

a guest
Dec 9th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if (!isset($_SESSION['username']) || !isset($_SESSION['password'])) {
  4. header('location: http://www.astraldevgroup.com');
  5. } else {
  6. ?>
  7. <html>
  8. <head>
  9. <link rel="stylesheet" type="text/css" href="style.css">
  10. </head>
  11. <title>Astral Dev - Chat</title>
  12. Welcome <?php echo $_SESSION['username']; ?>
  13. <input id="clearchat" type="submit" value="Clear Chat" />
  14. <div id="chatbox" width="430px" height="270px"><?php
  15. if (file_exists("chatlog.html") && filesize("chatlog.html") > 0) {
  16. $handle = fopen("chatlog.html", "r");
  17. $contents = fread($handle, filesize("chatlog.html"));
  18. fclose($handle);
  19. echo $contents;
  20. }
  21. ?></div>
  22.  
  23. <form name="message">
  24. <input name="usermsg" type="text" id="usermsg" size="63" />
  25. <input name="submitmsg" type="submit" id="submitmsg" value="Send" />
  26. </form>
  27.  
  28. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
  29. <script>
  30. $(document).ready(function() {
  31. $("#submitmsg").click(function() {
  32. var message = $("#usermsg").val();
  33. $.post("sendchatmsg.php", {cmsg: message});
  34. $("#usermsg").attr("value", "");
  35. return false;
  36. });
  37.  
  38. $("#clearchat").click(function() {
  39. $.post("clearchat.php");
  40. });
  41.  
  42. function loadLog() {
  43. var lastScrollHeight = $("#chatbox").attr("scrollHeight") - 20;
  44.  
  45. $.ajax({
  46. url: "chatlog.html",
  47. cache: false,
  48. success: function(html) {
  49. $("#chatbox").html(html);
  50.  
  51. //Auto scroll
  52. var newScrollHeight = $("#chatbox").attr("scrollHeight") - 20;
  53.  
  54. if (newScrollHeight > oldScrollHeight) {
  55. $("#chatbox").animate({scrollTop: newScrollHeight}, "normal");
  56. }
  57. },
  58. });
  59. }
  60.  
  61. setInterval(loadLog, 50);
  62. });
  63. </script>
  64. </html>
  65. <?php
  66. }
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement