Chat Machine

Discussion in 'PHP' started by robinspaul, Oct 8, 2008.

  1. #1
    Hi,
    I am thinking of developing a chat machine in php. Can anyone help me with some sample code, please?
    Thanks
     
    robinspaul, Oct 8, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    i suggest you use ajax.. with a time out in the ajax function
    visit this url http://www.w3schools.com/ajax/ajax_example_suggest.asp

    in the event, instead of onKeyUp, make this a onSubmit or onClick

    then set the timeout inside the js function
    t=setTimeout(ajaxfunction(),1000);
    this will refresh the container every 1 sec
     
    bartolay13, Oct 8, 2008 IP
  3. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    so, here is the logic:
    The page will contain like 2 DIVs.

    All of the chat messages will be saved at the first DIV. The second DIV will contain the chat form, where we can submit a message.

    You will need AJAX to do the message fetching in the background, and set a timeout (like 1000ms) to the javascript function (which do the fetching) to make it real-time.

    The javascript codes will fetch the messages from a PHP code that fetches the messages from the database (or maybe directly to the Text file if you're using flat file database), and the javascript will routinely write the returned data from the PHP to the DIV (ie. 1000ms each refresh).
     
    djzmo, Oct 8, 2008 IP
  4. robinspaul

    robinspaul Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I did not understand it clearly. Is there any place I can download the code?
     
    robinspaul, Nov 13, 2008 IP