Centar za edukaciju-BiH


Stranice (1):1

#1 28.09.2010 23:27
laponac84 Van mreze
Clan
Registrovan od:20.11.2008
Postovi:86


Predmet:Jednostavna CHAT skripta
Ova tri fajla samo iskopirajte i radice Vam perfektno Smiling

Naziv fajla: index.php
PreuzmiIzvorni kôd (PHP):
  1. <?
  2.  
  3. if(isset($_GET['logout'])){    
  4.        
  5.         //Poruka o napustanju cata
  6.         $fp = fopen("log.html", 'a');
  7.         fwrite($fp, "<div class='msgln'><i>Korisnik ". $_SESSION['name'] ." je napustio cat sesiju.</i><br></div>");
  8.         fclose($fp);
  9.        
  10.         session_destroy();
  11.         header("Location: index.php"); //preusmerava korisnika na pocetnu stranu
  12. }
  13.  
  14. function loginForm(){
  15.         echo'
  16.         <div id="loginform">
  17.         <form action="index.php" method="post">
  18.                 <p>Unesite Vas nick da bi otpoceli dopisivanje:</p>
  19.                 <label for="name">Nick:</label>
  20.                 <input type="text" name="name" id="name" />
  21.                 <input type="submit" name="enter" id="enter" value="Enter" />
  22.         </form>
  23.         </div>
  24.         ';
  25. }
  26.  
  27. if(isset($_POST['enter'])){
  28.         if($_POST['name'] != ""){
  29.                 $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
  30.         }
  31.         else{
  32.                 echo '<span class="error">Molimo Vas unesite Nick</span>';
  33.         }
  34. }
  35. ?>
  36. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  37. <html xmlns="http://www.w3.org/1999/xhtml">
  38. <head>
  39. <title>Chat - Customer Module</title>
  40. <link type="text/css" rel="stylesheet" href="style.css" />
  41. </head>
  42.  
  43. <?php
  44. if(!isset($_SESSION['name'])){
  45.         loginForm();
  46. }
  47. else{
  48. ?>
  49. <div id="wrapper">
  50.         <div id="menu">
  51.                 <p class="welcome">Dobrodosli, <b><?php echo $_SESSION['name']; ?></b></p>
  52.                 <p class="logout"><a id="exit" href="#">Napusti Chat</a></p>
  53.                 <div style="clear:both"></div>
  54.         </div> 
  55.         <div id="chatbox"><?php
  56.         if(file_exists("log.html") && filesize("log.html") > 0){
  57.                 $handle = fopen("log.html", "r");
  58.                 $contents = fread($handle, filesize("log.html"));
  59.                 fclose($handle);
  60.                
  61.                 echo $contents;
  62.         }
  63.         ?></div>
  64.        
  65.         <form name="message" action="">
  66.                 <input name="usermsg" type="text" id="usermsg" size="63" />
  67.                 <input name="submitmsg" type="submit"  id="submitmsg" value="Posalji" />
  68.         </form>
  69. </div>
  70. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
  71. <script type="text/javascript">
  72. // jQuery Document
  73. $(document).ready(function(){
  74.         //If user submits the form
  75.         $("#submitmsg").click(function(){      
  76.                 var clientmsg = $("#usermsg").val();
  77.                 $.post("post.php", {text: clientmsg});                         
  78.                 $("#usermsg").attr("value", "");
  79.                 return false;
  80.         });
  81.        
  82.         //Load the file containing the chat log
  83.         function loadLog(){            
  84.                 var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
  85.                 $.ajax({
  86.                         url: "log.html",
  87.                         cache: false,
  88.                         success: function(html){               
  89.                                 $("#chatbox").html(html); //Insert chat log into the #chatbox div                              
  90.                                 var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
  91.                                 if(newscrollHeight > oldscrollHeight){
  92.                                         $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
  93.                                 }                              
  94.                         },
  95.                 });
  96.         }
  97.         setInterval (loadLog, 2500);    //Reload file every 2.5 seconds
  98.        
  99.         //Proverava da li korsinik zaista zeli da napusti sesiju
  100.         $("#exit").click(function(){
  101.                 var exit = confirm("Da li ste sigurni da zelite da napustite sesiju?");
  102.                 if(exit==true){window.location = 'index.php?logout=true';}             
  103.         });
  104. });
  105. </script>
  106. <?php
  107. }
  108. ?>
  109. </body>
  110. </html>
↑  ↓

#2 28.09.2010 23:28
laponac84 Van mreze
Clan
Registrovan od:20.11.2008
Postovi:86


Predmet:Re: Jednostavna CHAT skripta
Naziv fajla: post.php
PreuzmiIzvorni kôd (PHP):
  1. <?
  2. if(isset($_SESSION['name'])){
  3.         $text = $_POST['text'];
  4.        
  5.         $fp = fopen("log.html", 'a');
  6.         fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
  7.         fclose($fp);
  8. }
  9. ?>
↑  ↓

#3 28.09.2010 23:29
laponac84 Van mreze
Clan
Registrovan od:20.11.2008
Postovi:86


Predmet:Re: Jednostavna CHAT skripta
i poslednji fajl
naziv fajla: style.css
PreuzmiIzvorni kôd (CSS):
  1. /* CSS Document */  
  2. body {  
  3.     font:12px arial;  
  4.     color: #222;  
  5.     text-align:center;  
  6.     padding:35px; }  
  7.  
  8. form, p, span {  
  9.     margin:0;  
  10.     padding:0; }  
  11.  
  12. input { font:12px arial; }  
  13.  
  14. a {  
  15.     color:#0000FF;  
  16.     text-decoration:none; }  
  17.  
  18.     a:hover { text-decoration:underline; }  
  19.  
  20. #wrapper, #loginform {  
  21.     margin:0 auto;  
  22.     padding-bottom:25px;  
  23.     background:#EBF4FB;  
  24.     width:504px;  
  25.     border:1px solid #ACD8F0; }  
  26.  
  27. #loginform { padding-top:18px; }  
  28.  
  29.     #loginform p { margin: 5px; }  
  30.  
  31. #chatbox {  
  32.     text-align:left;  
  33.     margin:0 auto;  
  34.     margin-bottom:25px;  
  35.     padding:10px;  
  36.     background:#fff;  
  37.     height:270px;  
  38.     width:430px;  
  39.     border:1px solid #ACD8F0;  
  40.     overflow:auto; }  
  41.  
  42. #usermsg {  
  43.     width:395px;  
  44.     border:1px solid #ACD8F0; }  
  45.  
  46. #submit { width: 60px; }  
  47.  
  48. .error { color: #ff0000; }  
  49.  
  50. #menu { padding:12.5px 25px 12.5px 25px; }  
  51.  
  52. .welcome { float:left; }  
  53.  
  54. .logout { float:rightright; }  
  55.  
  56. .msgln { margin:0 0 2px 0; }  
↑  ↓

Stranice (1):1


Sva vremena su GMT +01:00. Trenutno vrijeme: 9: 58 pm.