Results 1 to 2 of 2

Thread: PHP chat

  1. #1
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default PHP chat

    I have modified a script that uses PHP, mysqli, and html to create a chat. Is there any way I can change it so it does not do meta refreshes to get the annoying blink from the loading?

    If not, is there any other easy to work with chat script for another language I can use to access my mysql database?

    Here is an example of what I have now:

    Code:
    <META HTTP-EQUIV=Refresh CONTENT="8;url=chatmsgs2.php">
    <link rel=stylesheet>
    <body background='bgic.JPG' border=1 bordercolor=white>
    
    
    <?php
    
    $csel = mysqli_query($db, "select * from chat order by id desc limit 50") or die("Could not get user stats");
    
    
    while ($chat = mysqli_fetch_array($csel)) {
    
    
    
    if($chat['viewer']!=""){
    
    if($chat['viewer']==$_COOKIE['member_id']){
    
    print "<p align=left>$chat[user] $chat[chat]<p align=left>";
    
    
    }
    
    }elseif($chat['chat'] == "") {
    
    if($chat['sender']==$userstats3['Playername'] || $chat['reciever']==$userstats3['Playername']){
    
    $blahblah=mysqli_fetch_array(mysqli_query($db, "select * from Users where playername='$chat[reciever]'"));
    
    if($blahblah['ID']==""){
    
    print "<p align=left><font style=\"color: gray\">No such user.</font><p align=left>";
    
    }else{
    
    if($chat['reciever']==$userstats3['Playername']){
    
    
    print "<p align=left><font style=\"color: gray\"><a href='chat.php?Dude=$chat[sender]' target=_parent><font style=\"color: gray; text-decoration: underline;\">$chat[sender]</font></a> to $chat[reciever]$chat[message]</font><p align=left>";
    
    }else{
    
    
    print "<p align=left><font style=\"color: gray\">$chat[sender] to <a href='chat.php?Dude=$chat[reciever]' target=_parent><font style=\"color: gray; text-decoration: underline;\">$chat[reciever]</font></a>$chat[message]</font><p align=left>";
    
    }
    
    }
    
    }
    
    }else{
    
    print "<p align=left>$chat[user] $chat[chat]<p align=left>";
    
    }
    
    }
    
    ?>
    Last edited by Demonicman; 12-20-2014 at 10:53 PM.
    http://www.insanecombat.com << bored? check out ma game

  2. #2
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    Nobody responded so I figured it out myself. For future reference, here is a small bit of code I added.

    chat.php = chatting form + div of chat called "chatlogs"
    chatmsgs2.php = list of chat from db obtained using while() + fetch array

    At the top of chat.php put this:

    Code:
    <script>
    
    	var xmlhttp = new XMLHttpRequest();
    			
    	xmlhttp.onreadystatechange = function(){
    		if(xmlhttp.readyState==4&&xmlhttp.status==200){
    				document.getElementById('chatlogs').innerHTML = xmlhttp.responseText;
    			}
    		}
    	xmlhttp.open('chatmsgs2.php','chatmsgs2.php',true);
    	xmlhttp.send();
    
    	$(document).ready(function(e) {
            $.ajaxSetup({cache:false});
    		setInterval(function() {$('#chatlogs').load('chatmsgs2.php');}, 2000);
            });
    </script>
    Important: change 2000 to however much you want (2000 = 2 seconds)
    the div must be named chatlogs

    Found on youtube: https://www.youtube.com/watch?v=_XBeGcczFJo
    http://www.insanecombat.com << bored? check out ma game

  3. The Following User Says Thank You to Demonicman For This Useful Post:

    keyboard (12-26-2014)

Similar Threads

  1. Looking for a live chat OR help with current live chat.
    By mat420 in forum Looking for such a script or service
    Replies: 3
    Last Post: 11-12-2010, 01:31 PM
  2. Chat application
    By kiranpeter in forum JavaScript
    Replies: 0
    Last Post: 06-23-2009, 05:19 AM
  3. chat script?
    By Argyrodes in forum JavaScript
    Replies: 1
    Last Post: 12-25-2006, 08:22 AM
  4. Chat App?
    By akash in forum Other
    Replies: 1
    Last Post: 02-14-2006, 10:25 PM
  5. irc chat code?
    By darco9x2 in forum HTML
    Replies: 3
    Last Post: 02-27-2005, 08:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •