masslugi

Index.php -Chat On

May 13th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. <?
  2. session_start();
  3.  
  4. if(isset($_GET['logout'])){
  5.  
  6. // Pesan simpel ada saat keluar
  7. $fp = fopen("log.html", 'a');
  8. fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." telah keluar dari ruang obrolan.</i><br></div>");
  9. fclose($fp);
  10.  
  11. session_destroy();
  12. header("Location: index.php"); //Membawa user
  13. }
  14.  
  15. function loginForm(){
  16. echo'
  17. <div id="loginform">
  18. <form action="index.php" method="post">
  19. <p>Ketik nama anda untuk bergabung Bersama Mia Khalifa:</p>
  20. <label for="name">Nama:</label>
  21. <input type="text" name="name" id="name" />
  22. <input type="submit" name="enter" id="enter" value="Enter" />
  23. </form><br>By <a href="http://www.facebook.com/www.lugix">Lugi Shareking-go.net</a></br>
  24. </div>
  25. ';
  26. }
  27.  
  28. if(isset($_POST['enter'])){
  29. if($_POST['name'] != ""){
  30. $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
  31. $fp = fopen("log.html", 'a');
  32. fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." masuk ruang obrolan.</i><br></div>");
  33. fclose($fp);
  34. }
  35. else{
  36. echo '<span class="error">Silahkan tulis nama anda dulu!</span>';
  37. }
  38. }
  39. ?>
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml">
  42. <head>
  43. <title>Chat - Shareking-go.net</title>
  44. <style>
  45. /* Dokument CSS */
  46. @import url(http://fonts.googleapis.com/css?family=Share+Tech+Mono);
  47. body {
  48. background: #000000;
  49. font:12px ;
  50. color: #c7c7d8;
  51. text-align:center;
  52. }
  53.  
  54. form, p, span {
  55. margin:0;
  56. padding:0; }
  57.  
  58. input { font:12px ; }
  59.  
  60. a {
  61. color: #ffffff;
  62. text-decoration: none;
  63. }
  64.  
  65. a:hover { text-decoration:underline; }
  66.  
  67. #wrapper, #loginform {
  68. margin:0 auto;
  69. padding-bottom:35px;
  70. background:darkblue;
  71. width:554px;
  72. border:1px solid #000000; }
  73.  
  74. #loginform { padding-top:18px; }
  75.  
  76. #loginform p { margin: 5px; }
  77.  
  78.  
  79. #chatbox {
  80. text-align: left;
  81. margin: 0 auto;
  82. margin-bottom: 5px;
  83. padding: 10px;
  84. background: #000000;
  85. height: 300px;
  86. width: 530px;
  87. border: 1px solid #000000;
  88. overflow: auto;
  89. }
  90. #usermsg {
  91. color: #ffffff;
  92. width:395px;
  93. background: #191919;
  94. border:1px solid #silver; }
  95.  
  96. input[type=submit] {
  97. background: #191919;
  98. color: #ffffff;
  99. border: 1px solid #ffffff;
  100. margin: 5px auto;
  101. padding-left: 5px;
  102. font-family: 'Share Tech Mono';
  103. font-size: 13px;
  104. cursor:pointer;
  105. }
  106.  
  107. .error { color: #ff0000; }
  108.  
  109. #menu { padding:12.5px 25px 12.5px 25px; }
  110.  
  111. .welcome { float:left; }
  112.  
  113. .logout { float:right; }
  114.  
  115. .msgln { margin:0 0 2px 0; }
  116. textarea {
  117. border: 1px solid #ffffff;
  118. padding-left: 5px;
  119. margin: 10px auto;
  120. resize: none;
  121. background: transparent;
  122. color: #ffffff;
  123. font-family: 'Share Tech Mono';
  124. font-size: 13px;
  125. }
  126. </style>
  127. </head>
  128. <h2> Chat Online Bersama Mia Khalifa</h2>
  129. <?php
  130. if(!isset($_SESSION['name'])){
  131. loginForm();
  132. }
  133. else{
  134. ?>
  135. <div id="wrapper">
  136. <div id="menu">
  137. <p class="welcome">Selamat Datang, <b><?php echo $_SESSION['name']; ?></b></p>
  138. <p class="logout"><a id="exit" href="#">Keluar Chat</a></p>
  139. <div style="clear:both"></div>
  140. </div>
  141. <div id="chatbox"><?php
  142. if(file_exists("log.html") && filesize("log.html") > 0){
  143. $handle = fopen("log.html", "r");
  144. $contents = fread($handle, filesize("log.html"));
  145. fclose($handle);
  146.  
  147. echo $contents;
  148. }
  149. ?></div>
  150.  
  151. <form name="message" action="">
  152. <textarea style='width: 450px; height: 120px;' name="usermsg" type="text" id="usermsg"></textarea><br>
  153. <input style="width: 430px;" name="submitmsg" type="submit" id="submitmsg" value="Kirim" />
  154. </form>
  155. </div>
  156. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
  157. <script type="text/javascript">
  158. // jQuery Document
  159. $(document).ready(function(){
  160. //If user submits the form
  161. $("#submitmsg").click(function(){
  162. var clientmsg = $("#usermsg").val();
  163. $.post("post.php", {text: clientmsg});
  164. $("#usermsg").attr("value", "");
  165. return false;
  166. });
  167.  
  168. //Load the file containing the chat log
  169. function loadLog(){
  170. var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
  171. $.ajax({
  172. url: "log.html",
  173. cache: false,
  174. success: function(html){
  175. $("#chatbox").html(html); //Insert chat log into the #chatbox div
  176. var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
  177. if(newscrollHeight > oldscrollHeight){
  178. $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
  179. }
  180. },
  181. });
  182. }
  183. setInterval (loadLog, 2500); //Reload file every 2.5 seconds
  184.  
  185. //If user wants to end session
  186. $("#exit").click(function(){
  187. var exit = confirm("Apakah anda yakin mengakhiri obrolan ini?");
  188. if(exit==true){window.location = 'index.php?logout=true';}
  189. });
  190. });
  191. </script>
  192. <?php
  193. }
  194. ?>
  195. <script id="_wauofs">var _wau = _wau || [];
  196. _wau.push(["tab", "3aqg1rh9oalk", "ofs", "left-middle"]);
  197. (function() {var s=document.createElement("script"); s.async=true;
  198. s.src="//widgets.amung.us/tab.js";
  199. document.getElementsByTagName("head")[0].appendChild(s);
  200. })();</script>
  201. </body>
  202. </html>
Advertisement
Add Comment
Please, Sign In to add comment