Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- session_start();
- if(isset($_GET['logout'])){
- // Pesan simpel ada saat keluar
- $fp = fopen("log.html", 'a');
- fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." telah keluar dari ruang obrolan.</i><br></div>");
- fclose($fp);
- session_destroy();
- header("Location: index.php"); //Membawa user
- }
- function loginForm(){
- echo'
- <div id="loginform">
- <form action="index.php" method="post">
- <p>Ketik nama anda untuk bergabung Bersama Mia Khalifa:</p>
- <label for="name">Nama:</label>
- <input type="text" name="name" id="name" />
- <input type="submit" name="enter" id="enter" value="Enter" />
- </form><br>By <a href="http://www.facebook.com/www.lugix">Lugi Shareking-go.net</a></br>
- </div>
- ';
- }
- if(isset($_POST['enter'])){
- if($_POST['name'] != ""){
- $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
- $fp = fopen("log.html", 'a');
- fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." masuk ruang obrolan.</i><br></div>");
- fclose($fp);
- }
- else{
- echo '<span class="error">Silahkan tulis nama anda dulu!</span>';
- }
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Chat - Shareking-go.net</title>
- <style>
- /* Dokument CSS */
- @import url(http://fonts.googleapis.com/css?family=Share+Tech+Mono);
- body {
- background: #000000;
- font:12px ;
- color: #c7c7d8;
- text-align:center;
- }
- form, p, span {
- margin:0;
- padding:0; }
- input { font:12px ; }
- a {
- color: #ffffff;
- text-decoration: none;
- }
- a:hover { text-decoration:underline; }
- #wrapper, #loginform {
- margin:0 auto;
- padding-bottom:35px;
- background:darkblue;
- width:554px;
- border:1px solid #000000; }
- #loginform { padding-top:18px; }
- #loginform p { margin: 5px; }
- #chatbox {
- text-align: left;
- margin: 0 auto;
- margin-bottom: 5px;
- padding: 10px;
- background: #000000;
- height: 300px;
- width: 530px;
- border: 1px solid #000000;
- overflow: auto;
- }
- #usermsg {
- color: #ffffff;
- width:395px;
- background: #191919;
- border:1px solid #silver; }
- input[type=submit] {
- background: #191919;
- color: #ffffff;
- border: 1px solid #ffffff;
- margin: 5px auto;
- padding-left: 5px;
- font-family: 'Share Tech Mono';
- font-size: 13px;
- cursor:pointer;
- }
- .error { color: #ff0000; }
- #menu { padding:12.5px 25px 12.5px 25px; }
- .welcome { float:left; }
- .logout { float:right; }
- .msgln { margin:0 0 2px 0; }
- textarea {
- border: 1px solid #ffffff;
- padding-left: 5px;
- margin: 10px auto;
- resize: none;
- background: transparent;
- color: #ffffff;
- font-family: 'Share Tech Mono';
- font-size: 13px;
- }
- </style>
- </head>
- <h2> Chat Online Bersama Mia Khalifa</h2>
- <?php
- if(!isset($_SESSION['name'])){
- loginForm();
- }
- else{
- ?>
- <div id="wrapper">
- <div id="menu">
- <p class="welcome">Selamat Datang, <b><?php echo $_SESSION['name']; ?></b></p>
- <p class="logout"><a id="exit" href="#">Keluar Chat</a></p>
- <div style="clear:both"></div>
- </div>
- <div id="chatbox"><?php
- if(file_exists("log.html") && filesize("log.html") > 0){
- $handle = fopen("log.html", "r");
- $contents = fread($handle, filesize("log.html"));
- fclose($handle);
- echo $contents;
- }
- ?></div>
- <form name="message" action="">
- <textarea style='width: 450px; height: 120px;' name="usermsg" type="text" id="usermsg"></textarea><br>
- <input style="width: 430px;" name="submitmsg" type="submit" id="submitmsg" value="Kirim" />
- </form>
- </div>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
- <script type="text/javascript">
- // jQuery Document
- $(document).ready(function(){
- //If user submits the form
- $("#submitmsg").click(function(){
- var clientmsg = $("#usermsg").val();
- $.post("post.php", {text: clientmsg});
- $("#usermsg").attr("value", "");
- return false;
- });
- //Load the file containing the chat log
- function loadLog(){
- var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
- $.ajax({
- url: "log.html",
- cache: false,
- success: function(html){
- $("#chatbox").html(html); //Insert chat log into the #chatbox div
- var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
- if(newscrollHeight > oldscrollHeight){
- $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
- }
- },
- });
- }
- setInterval (loadLog, 2500); //Reload file every 2.5 seconds
- //If user wants to end session
- $("#exit").click(function(){
- var exit = confirm("Apakah anda yakin mengakhiri obrolan ini?");
- if(exit==true){window.location = 'index.php?logout=true';}
- });
- });
- </script>
- <?php
- }
- ?>
- <script id="_wauofs">var _wau = _wau || [];
- _wau.push(["tab", "3aqg1rh9oalk", "ofs", "left-middle"]);
- (function() {var s=document.createElement("script"); s.async=true;
- s.src="//widgets.amung.us/tab.js";
- document.getElementsByTagName("head")[0].appendChild(s);
- })();</script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment